Exemplo n.º 1
0
        public void TestCompressToWebP()
        {
            WebPFormat webP    = new WebPFormat();
            var        srcPath = @"C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg";

            //using (System.IO.FileStream fs = new System.IO.FileStream(,
            //    System.IO.FileMode.Open, System.IO.FileAccess.Read))
            //{
            Image img = Image.FromFile(srcPath);

            //var image = webP.Load(fs);

            for (int i = 10; i <= 100; i += 10)
            {
                webP.Quality = i;
                webP.Save(@"C:\Users\Public\Pictures\Sample Pictures\Compress-" + i + ".webp", img, 4);
            }

            for (int i = 90; i <= 99; i += 1)
            {
                webP.Quality = i;
                webP.Save(@"C:\Users\Public\Pictures\Sample Pictures\90-99\Compress-" + i + ".webp", img, 4);
            }
            //}
        }
Exemplo n.º 2
0
        public void GenerateWebP()
        {
            var st = new StackFrame(1);

            Console.WriteLine($"{st.GetMethod().DeclaringType.FullName}.{st.GetMethod().Name}");
            Console.WriteLine();

            var encoder     = new WebPFormat();
            var fileName    = "Testing.jpg";
            var outFileName = "Testing.webp";

            File.Delete(outFileName);

            using (Stream BitmapStream = File.Open(fileName, FileMode.Open))
            {
                Image img = Image.FromStream(BitmapStream);
                encoder.Save(new FileStream(outFileName, FileMode.Create), img, 1);
            }
        }
Exemplo n.º 3
0
        private void ThreadedFileMove(object o)
        {
            if (o.GetType() != typeof(string[]))
            {
                return;
            }
            string[] fromTo = o as string[];
            if (fromTo.Length != 2)
            {
                return;
            }

            lock (FileMoveLock)
            {
                try
                {
                    if (File.Exists(fromTo[0]) && !File.Exists(fromTo[1]))
                    {
                        if (fromTo[0].EndsWith(".jfif"))
                        {
                            var jfif       = Image.FromFile(fromTo[0]);
                            var targetPath = fromTo[1].Substring(0, fromTo[1].LastIndexOf('.')) + ".jpeg";
                            jfif.Save(targetPath, ImageFormat.Jpeg);
                            jfif.Dispose();
                            File.Delete(fromTo[0]);
                        }
                        else if (fromTo[0].EndsWith(".webp"))
                        {
                            lock (PictureConversionLock)
                            {
                                var stream = new FileStream(fromTo[0], FileMode.Open);
                                try
                                {
                                    var webp       = new WebPFormat().Load(stream);
                                    var targetPath = fromTo[1].Substring(0, fromTo[1].LastIndexOf('.')) + ".jpeg";
                                    webp.Save(targetPath, ImageFormat.Jpeg);
                                    webp.Dispose();
                                    stream.Dispose();
                                    File.Delete(fromTo[0]);
                                }
                                catch
                                {
                                    stream.Dispose();
                                    File.Move(fromTo[0], fromTo[1]);
                                }
                            }
                        }
                        else if (fromTo[0].EndsWith(".jpg_large"))
                        {
                            File.Move(fromTo[0], fromTo[1].Split('_').Reverse().Skip(1).Reverse().Combine("_"));
                        }
                        else if (fromTo[0].EndsWith(".crdownload") || fromTo[0].EndsWith(".opdownload"))
                        {
                            return;
                        }
                        else
                        {
                            File.Move(fromTo[0], fromTo[1]);
                        }

                        // Display toast
                        new Process()
                        {
                            StartInfo = new ProcessStartInfo("toast.exe", $"-h \"Downloaded File\" -m \"{Path.GetFileNameWithoutExtension(fromTo[1])}\" " +
                                                             $"-f \"To {fromTo[1]}\" -n \"DownloadFolderSorter\"")
                            {
                                UseShellExecute = false, CreateNoWindow = true
                            }
                        }.Start();
                    }
                }
                catch { }
            }
        }