private void BitmapImportButton_Click(object sender, EventArgs eventArgs)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            try
            {
                using (var imageConverterWindow = new ImageConverterWindow(true, LastSelectedImageMetadata.Width, LastSelectedImageMetadata.Height))
                {
                    if (imageConverterWindow.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    using (var monochrome = imageConverterWindow.GetConvertedImage())
                    {
                        var imageData = BitmapProcessor.CreateRawFromBitmap(monochrome);
                        ImagePixelGrid.CreateUndo();
                        ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(x => FirmwareImageProcessor.PasteImage(x, imageData), LastSelectedImageMetadata, true);
                    }
                }
            }
            catch (Exception ex)
            {
                InfoBox.Show("Unable to import bitmap image.\n" + ex.Message);
            }
        }
        private void ShiftDownButton_Click(object sender, EventArgs e)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            ImagePixelGrid.CreateUndo();
            ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(FirmwareImageProcessor.ShiftDown, LastSelectedImageMetadata);
        }
Ejemplo n.º 3
0
        private void BitmapImportButton_Click(object sender, EventArgs eventArgs)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            using (var op = new OpenFileDialog {
                Filter = Consts.BitmapImportFilter
            })
            {
                if (op.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    var bitmapFile = op.FileName;
                    using (var bitmap = (Bitmap)Image.FromFile(bitmapFile))
                    {
                        if (bitmap.Width > 2048 || bitmap.Height > 2048)
                        {
                            InfoBox.Show("Selected images is too big. Choose an image that has dimension lower than 2048x2048.");
                            return;
                        }
                        using (var scaledBitmap = BitmapProcessor.ScaleBitmapIfNecessary(bitmap, new Size(LastSelectedImageMetadata.Width, LastSelectedImageMetadata.Height)))
                            using (var monochrome = BitmapProcessor.ConvertTo1Bit(scaledBitmap))
                            {
                                var imageData = BitmapProcessor.CreateRawFromBitmap(monochrome);
                                ImagePixelGrid.CreateUndo();
                                ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(x => FirmwareImageProcessor.PasteImage(x, imageData), LastSelectedImageMetadata, true);
                            }
                    }
                }
                catch (Exception ex)
                {
                    InfoBox.Show("Unable to import bitmap image.\n" + ex.Message);
                }
            }
        }
        private void BitmapImportButton_Click(object sender, EventArgs eventArgs)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            using (var op = new OpenFileDialog {
                Filter = Consts.BitmapImportFilter
            })
            {
                if (op.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    var bitmapFile = op.FileName;
                    using (var bitmap = (Bitmap)Image.FromFile(bitmapFile))
                    {
                        if (bitmap.Width > Consts.MaximumImageWidthAndHeight || bitmap.Height > Consts.MaximumImageWidthAndHeight)
                        {
                            InfoBox.Show("Image is too big. Image width and height must be lower or equals to {0} pixels.", Consts.MaximumImageWidthAndHeight);
                            return;
                        }
                        var imageData = FirmwareImageProcessor.ImportBitmap(bitmap);
                        ImagePixelGrid.CreateUndo();
                        ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(x => FirmwareImageProcessor.PasteImage(x, imageData), LastSelectedImageMetadata, true);
                    }
                }
                catch (Exception ex)
                {
                    InfoBox.Show("Unable to import bitmap image.\n" + ex.Message);
                }
            }
        }