Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Error: Please specify input and output png files");
                return;
            }

            string inputFile  = args[0];
            string outputFile = args[1];

            Bitmap img = new Bitmap(inputFile);

            img = copyType(img);

            float scale = 2f;

            if (args.Length >= 3)
            {
                scale = float.Parse(args[2]);
            }

            float pushStrength     = scale / 6f;
            float pushGradStrength = scale / 2f;

            if (args.Length >= 4)
            {
                pushStrength = float.Parse(args[4]);
            }

            if (args.Length >= 5)
            {
                pushGradStrength = float.Parse(args[3]);
            }

            img = upscale(img, (int)(img.Width * scale), (int)(img.Height * scale));
            //img.Save("Bicubic.png", ImageFormat.Png);

            // Push twice to get sharper lines.
            for (int i = 0; i < 2; i++)
            {
                // Compute Luminance and store it to alpha channel.
                ImageProcess.ComputeLuminance(ref img);
                //img.Save("Luminance.png", ImageFormat.Png);

                // Push (Notice that the alpha channel is pushed with rgb channels).
                ImageProcess.PushColor(ref img, clamp((int)(pushStrength * 255), 0, 0xFFFF));
                //img.Save("Push.png", ImageFormat.Png);

                // Compute Gradient of Luminance and store it to alpha channel.
                ImageProcess.ComputeGradient(ref img);
                //img.Save("Grad.png", ImageFormat.Png);

                // Push Gradient
                ImageProcess.PushGradient(ref img, clamp((int)(pushGradStrength * 255), 0, 0xFFFF));
            }
            img.Save(outputFile, ImageFormat.Png);
        }
Exemple #2
0
        public static void Pross(string file, string[] args, float scale, int push, string outputPath)
        {
            // get primary file name
            string fileName = file.Substring(file.LastIndexOf("\\") + 1);
            Bitmap img      = new Bitmap(file);

            try
            {
                img = copyType(img);

                if (args.Length >= 3)
                {
                    scale = Convert.ToSingle(args[2]);
                }

                float pushStrength     = scale / 6f;
                float pushGradStrength = scale / 2f;

                if (args.Length >= 4)
                {
                    pushStrength = Convert.ToSingle(args[3]);
                }

                if (args.Length >= 5)
                {
                    pushGradStrength = Convert.ToSingle(args[4]);
                }

                // 放大
                img = upscale(img, (int)(img.Width * scale), (int)(img.Height * scale));
                //img.Save("Bicubic.png", ImageFormat.Png);

                // Push twice to get sharper lines. 推两次以得到清晰的线条(值越大, 线条越细, 最大值8就够了)
                for (int j = 0; j < push; j++)
                {
                    // Compute Luminance and store it to alpha channel.
                    img = ImageProcess.ComputeLuminance(img);
                    //img.Save("Luminance.png", ImageFormat.Png);

                    // Push (Notice that the alpha channel is pushed with rgb channels).
                    Bitmap img2 = ImageProcess.PushColor(img, clamp((int)(pushStrength * 255), 0, 0xFFFF));
                    //save(img2, inputFile.Replace("images", "out") + ".Push.png", ImageFormat.Png);
                    img.Dispose();
                    img = img2;

                    // Compute Gradient of Luminance and store it to alpha channel.
                    img2 = ImageProcess.ComputeGradient(img);
                    //save(img2, inputFile.Replace("images", "out") + "Grad.png", ImageFormat.Png);
                    img.Dispose();
                    img = img2;

                    // Push Gradient
                    img2 = ImageProcess.PushGradient(img, clamp((int)(pushGradStrength * 255), 0, 0xFFFF));
                    img.Dispose();
                    img = img2;
                }
                save(img, outputPath + fileName, ImageFormat.Png);
            }
            catch (Exception exception)
            {
                Console.WriteLine("{0} 转换失败 \n", file);
                Console.WriteLine(exception.Message);
                Console.WriteLine(exception.StackTrace);
            }
            finally
            {
                img.Dispose();
            }

            Console.WriteLine("done {0}", outputPath + fileName);
        }