Пример #1
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);
                }
            }
        }