private void btnPrintPreview_Click(object sender, RoutedEventArgs e)
        {
            Screen screen = (Screen)cmbxScreenList.SelectedItem;

            Bitmap bmp = new Bitmap(txtbPreviewPath.Text);

            Point[] points = GraphicHelper.ComputeTargetPoints(new Size(800, 601), new Size(bmp.Width, bmp.Height), Rotation.DEG_0);

            Bitmap bmpResized = new Bitmap(800, 601);

            using (Graphics gr = Graphics.FromImage(bmpResized))
            {
                gr.DrawImage(bmp, points);
            }

            grayData = GrayScaleConverter.ConvertToGrayscale(bmpResized, GrayScaleConverter.ConvertionMethod.AverageBT601, 8);

            grayData = GrayScaleConverter.DitherSierraLight(grayData, 8, bmpResized.Width, bmpResized.Height);

            grayData = GrayScaleConverter.ReverseGrayScale(grayData, 8);

            grayData = GrayScaleConverter.CompactArray(grayData, 8);

            screen.SendImageBuffer(8, grayData);

            screen.DrawBuffer();
        }
示例#2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Bitmap bmp = new Bitmap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LSTB_Files.SelectedItem.ToString()));

            Bitmap newImage = new Bitmap(800, 600);

            using (Graphics gr = Graphics.FromImage(newImage))
            {
                gr.SmoothingMode     = SmoothingMode.HighQuality;
                gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                gr.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                gr.DrawImage(bmp, new Rectangle(0, 0, 800, 600));

                gr.Save();
            }

            GrayScaleConverter.ConvertionMethod method    = (GrayScaleConverter.ConvertionMethod)Enum.Parse(typeof(GrayScaleConverter.ConvertionMethod), CMBX_Method.SelectedItem.ToString());
            GrayScaleConverter.DitheringMethod  dithering = (GrayScaleConverter.DitheringMethod)Enum.Parse(typeof(GrayScaleConverter.DitheringMethod), CMBX_Dithering.SelectedItem.ToString());
            sw.Stop();

            long phase1ms = sw.ElapsedMilliseconds;

            List <Tuple <long, long, long> > timing = new List <Tuple <long, long, long> >();

            for (int i = 0; i < 10; i++)
            {
                sw.Restart();

                byte[] grayData = GrayScaleConverter.ConvertToGrayscale(newImage, method, 8);
                sw.Stop();

                long grayms = sw.ElapsedMilliseconds;

                sw.Restart();

                grayData = GrayScaleConverter.DitherSierraLight(grayData, 8, newImage.Width, newImage.Height);

                sw.Stop();
                long diterms = sw.ElapsedMilliseconds;

                sw.Restart();

                byte[] output = new byte[(int)Math.Ceiling(grayData.Length / 2.0)];

                int counter = 0;

                for (int j = 0; j < grayData.Length; j += 2)
                {
                    output[counter] = (byte)(grayData[j] << 4 | grayData[j + 1]);

                    counter++;
                }

                grayData = output;

                sw.Stop();

                long compressms = sw.ElapsedMilliseconds;



                timing.Add(new Tuple <long, long, long>(grayms, compressms, diterms));
            }

            MessageBox.Show("Phase 1 : " + phase1ms + "ms " + Environment.NewLine +
                            "Phase gray : min : " + timing.Select(item => item.Item1).Min() + "ms | max : " + timing.Select(item => item.Item1).Max() + "ms | avg : " + timing.Select(item => item.Item1).Average() + "ms" + Environment.NewLine +
                            "Phase compress : min : " + timing.Select(item => item.Item2).Min() + "ms | max : " + timing.Select(item => item.Item2).Max() + "ms | avg : " + timing.Select(item => item.Item2).Average() + "ms" + Environment.NewLine +
                            "Phase diter : min : " + timing.Select(item => item.Item3).Min() + "ms | max : " + timing.Select(item => item.Item3).Max() + "ms | avg : " + timing.Select(item => item.Item3).Average() + "ms"


                            );
        }