コード例 #1
0
ファイル: Form1.cs プロジェクト: remygrandin/EInk-screens
        private void BTN_GenAll_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LSTB_Files.SelectedItem.ToString()));

            int count = 1;

            if (!Directory.Exists(@".\out\"))
            {
                Directory.CreateDirectory(@".\out\");
            }

            foreach (int grayScale in new List <int>()
            {
                2, 4, 8, 16, 32, 64, 128, 256
            })
            {
                foreach (GrayScaleConverter.ConvertionMethod convValue in Enum.GetValues(typeof(GrayScaleConverter.ConvertionMethod)))
                {
                    foreach (GrayScaleConverter.DitheringMethod ditherValue in Enum.GetValues(typeof(GrayScaleConverter.DitheringMethod)))
                    {
                        foreach (bool serpentine in new List <bool>()
                        {
                            false, true
                        })
                        {
                            byte[] grayData = GrayScaleConverter.FromBitmap(bmp, convValue, ditherValue, serpentine, grayScale);

                            Bitmap grayBmp = GrayScaleConverter.GrayToBitmap(grayData, bmp.Width, bmp.Height, grayScale);

                            string convName   = Enum.GetName(typeof(GrayScaleConverter.ConvertionMethod), convValue);
                            string ditherName = Enum.GetName(typeof(GrayScaleConverter.DitheringMethod), ditherValue);

                            string strCount = count.ToString().PadLeft(3, '0');

                            grayBmp.Save(@".\out\" + LSTB_Files.SelectedItem.ToString() + "-" + strCount
                                         + "-" + grayScale
                                         + "-" + convName
                                         + "-" + ditherName
                                         + "-" + (serpentine ? "Serp" : "Regular")
                                         + ".png", ImageFormat.Png);

                            count++;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: remygrandin/EInk-screens
        private void render()
        {
            if (LSTB_Files.SelectedItem == null || String.IsNullOrWhiteSpace(LSTB_Files.SelectedItem.ToString()))
            {
                return;
            }

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

            int depth = int.Parse(CMBX_GrayScale.SelectedItem.ToString());

            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());
            bool serpentine = CHKB_Serpentine.Checked;


            byte[] grayData = GrayScaleConverter.FromBitmap(bmp, method, dithering, serpentine, depth);

            Bitmap grayBmp = GrayScaleConverter.GrayToBitmap(grayData, bmp.Width, bmp.Height, depth);

            PCBX_Output.Image = grayBmp;
        }
コード例 #3
0
        private async void BtnEcho_OnClick(object sender, RoutedEventArgs e)
        {
            Bitmap bmp = new Bitmap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mlp.jpg"));

            Bitmap newImage = new Bitmap(800, 601);

            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, 601));

                gr.Save();
            }

            byte[] grayData = GrayScaleConverter.FromBitmap(newImage, GrayScaleConverter.ConvertionMethod.Desaturation, GrayScaleConverter.DitheringMethod.Atkinson, false, 8);

            grayData = GrayScaleConverter.ReverseGrayScale(grayData, 8);

            //await Connector.testImage("", grayData);
        }
コード例 #4
0
        private void loadImage(string path)
        {
            //Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mlp.png")
            Bitmap bmp = new Bitmap(path);

            Bitmap bmpResized = new Bitmap(bmp, 800, 601);


            int depth = 8;

            GrayScaleConverter.ConvertionMethod method    = GrayScaleConverter.ConvertionMethod.DecompositionMax;
            GrayScaleConverter.DitheringMethod  dithering = GrayScaleConverter.DitheringMethod.Atkinson;
            bool serpentine = false;


            grayData = GrayScaleConverter.FromBitmap(bmpResized, method, dithering, serpentine, depth);

            Bitmap grayBmp = GrayScaleConverter.GrayToBitmap(grayData, bmpResized.Width, bmpResized.Height, depth);

            grayData = GrayScaleConverter.ReverseGrayScale(grayData, depth);

            imgPreview.Source = bitmapToImageSource(grayBmp);
        }