private void CreateMonochromeBitmap()
        {
            if (m_originalBitmap == null || m_doNotUpdateMonochrome)
            {
                return;
            }

            using (var scaledImage = BitmapProcessor.FitToSize(m_originalBitmap, new Size(m_width, m_height)))
            {
                if (m_monochromeBitmap != null)
                {
                    m_monochromeBitmap.Dispose();
                    m_monochromeBitmap = null;
                }

                var mode = (NamedItemContainer <MonochromeConversionMode>)ConversionTypeComboBox.SelectedItem;
                switch (mode.Data)
                {
                case MonochromeConversionMode.ThresholdBased:
                {
                    m_monochromeBitmap = BitmapProcessor.ConvertTo1Bit(scaledImage, MonochromeConversionMode.ThresholdBased, (int)ThresholdUpDown.Value);
                    break;
                }

                case MonochromeConversionMode.FloydSteinbergDithering:
                {
                    m_monochromeBitmap = BitmapProcessor.ConvertTo1Bit(scaledImage);
                    break;
                }

                default: throw new ArgumentOutOfRangeException();
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }