コード例 #1
0
        public GameBoyPrinterEmulatorWindow(IControllerReader reader)
        {
            if (Properties.Settings.Default.UpgradeRequired)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeRequired = false;
                Properties.Settings.Default.Save();
            }

            InitializeComponent();
            DataContext = this;

            _reader = reader ?? throw new ArgumentNullException(nameof(reader));

            SelectedPalette = Properties.Settings.Default.SelectedPalette;
            PrintSize       = Properties.Settings.Default.PrintSize;

            using (Bitmap bmp = new Bitmap(Properties.Resources.PrintImage))
            {
                _imageBuffer = new BitmapPixelMaker(480, 432);

                _imageBuffer.SetColor(palettes[SelectedPalette][0][3], palettes[SelectedPalette][1][3], palettes[SelectedPalette][2][3]);

                for (int i = 0; i < bmp.Width; ++i)
                {
                    for (int j = 0; j < bmp.Height; ++j)
                    {
                        System.Drawing.Color pixel = bmp.GetPixel(i, j);
                        if (pixel.R == 255 && pixel.G == 255 && pixel.B == 255)
                        {
                            _imageBuffer.SetRed(i, j, palettes[SelectedPalette][0][0]);
                            _imageBuffer.SetGreen(i, j, palettes[SelectedPalette][1][0]);
                            _imageBuffer.SetBlue(i, j, palettes[SelectedPalette][2][0]);
                        }
                    }
                }

                WriteableBitmap wbitmap = _imageBuffer.MakeBitmap(96, 96);

                // Create an Image to display the bitmap.
                _image = new System.Windows.Controls.Image
                {
                    Stretch = Stretch.None,
                    Margin  = new Thickness(0)
                };

                _             = GameBoyPrinterEmulatorWindowGrid.Children.Add(_image);
                _image.Source = wbitmap;

                _reader.ControllerStateChanged += Reader_ControllerStateChanged;
                _reader.ControllerDisconnected += Reader_ControllerDisconnected;

                CheckPalette(SelectedPalette);
                CheckSize(PrintSize);
            }
        }
コード例 #2
0
        private void DisplayError()
        {
            SelectedPalette = Properties.Settings.Default.SelectedPalette;
            PrintSize       = Properties.Settings.Default.PrintSize;

            using (Bitmap bmp = new Bitmap(Properties.Resources.ErrorImage))
            {
                _imageBuffer = new BitmapPixelMaker(480, 432);

                _imageBuffer.SetColor(palettes[SelectedPalette][0][3], palettes[SelectedPalette][1][3], palettes[SelectedPalette][2][3]);

                for (int i = 0; i < bmp.Width; ++i)
                {
                    for (int j = 0; j < bmp.Height; ++j)
                    {
                        System.Drawing.Color pixel = bmp.GetPixel(i, j);
                        if (pixel.R == 255 && pixel.G == 255 && pixel.B == 255)
                        {
                            _imageBuffer.SetRed(i, j, palettes[SelectedPalette][0][0]);
                            _imageBuffer.SetGreen(i, j, palettes[SelectedPalette][1][0]);
                            _imageBuffer.SetBlue(i, j, palettes[SelectedPalette][2][0]);
                        }
                    }
                }


                // imageBuffer.SetColor(0, 0, 0);
                // Convert the pixel data into a WriteableBitmap.
                WriteableBitmap wbitmap = _imageBuffer.MakeBitmap(96, 96);

                // Set the Image source.
                _image.Source = wbitmap;

                GameBoyPrinterEmulatorWindowGrid.Height = 432;
                GameBoyPrinterEmulatorWindowGrid.Width  = 480;
                Height = 432;
                Width  = 480;
            }
        }