Ejemplo n.º 1
0
        static public void Compute()
        {
            wasComputed = true;
            foreach (var imageFn in CmdOptions.options.inputFiles)
            {
                Bitmap inp = null;
                try
                {
                    inp = (Bitmap)Image.FromFile(imageFn);
                }
                catch (Exception)
                {
                }

                if (inp == null)
                {
                    inp = Draw.TestImageGray(1200, 900, 12);
                }

                Bitmap bmp;
                sw.Restart();

                long dots = Dither.TransformImage(inp, out bmp, inp.Width, inp.Height, CmdOptions.options.param);

                sw.Stop();
                float elapsed = 1.0e-3f * sw.ElapsedMilliseconds;

                bmp.SetResolution(1200, 1200);

                Util.Log(CmdOptions.options.param);
                Util.LogFormat("Name: '{0}', input: '{1}', elapsed: {2:f3}s, dots: {3}, dps: {4}, hash: {5:X16}",
                               CmdOptions.options.name, imageFn, elapsed, Util.kmg(dots), Util.kmg((long)(dots / elapsed)),
                               Draw.Hash(bmp));

                string fileName = CmdOptions.options.outputFileName;
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = Path.GetFileName(imageFn);
                }
                string outFn = Path.Combine(CmdOptions.options.outDir, fileName);
                string ext   = Path.GetExtension(outFn);
                if (ext.ToLower() != ".png")
                {
                    outFn = outFn.Substring(0, outFn.Length - ext.Length) + ".png";
                }
                bmp.Save(outFn, System.Drawing.Imaging.ImageFormat.Png);

                Util.LogFormat("Output: '{0} ({1}x{2}px, {3:f1}x{4:f1}cm)' .. saved",
                               outFn, bmp.Width, bmp.Height,
                               bmp.Width * 2.54 / 1200.0, bmp.Height * 2.54 / 1200.0);
                inp.Dispose();
                bmp.Dispose();
            }
        }
Ejemplo n.º 2
0
        private void transform()
        {
            if (inputImage != null)
            {
                Bitmap    ibmp = (Bitmap)inputImage;
                Bitmap    bmp;
                Stopwatch sw = new Stopwatch();
                sw.Start();

                long dots = Dither.TransformImage(ibmp, out bmp, ibmp.Width, ibmp.Height, textParam.Text);

                sw.Stop();
                float elapsed = 1.0e-3f * sw.ElapsedMilliseconds;

                bmp.SetResolution(1200, 1200);
                SetImage(bmp);

                SetText(string.Format(CultureInfo.InvariantCulture, "Elapsed: {0:f3}s, dots: {1}",
                                      elapsed, Util.kmg(dots)));
            }

            StopComputation();
        }