private void EyedropTimer_Tick(object sender, EventArgs e) { IntPtr winDc = GetWindowDC(GetDesktopWindow()); byte[] b = BitConverter.GetBytes(GetPixel(winDc, Cursor.Position.X, Cursor.Position.Y)); NSE_Framework.Data.GBAcolor c = new NSE_Framework.Data.GBAcolor(b[0], b[1], b[2]); PickedColor.BackColor = c.Color; }
private void button1_Click(object sender, EventArgs e) { ColorDialog di = new ColorDialog(); if (di.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { NSE_Framework.Data.GBAcolor color = new NSE_Framework.Data.GBAcolor(di.Color.R, di.Color.G, di.Color.B); byte[] output = NSE_Framework.Data.Translator.PaletteToByte(color); button1.Text = output[0].ToString("X2") + output[1].ToString("X2"); button1.BackColor = di.Color; this.Text = "Success!"; } else { this.Text = "FAIL"; } }
private void ButtonLoad_Click(object sender, EventArgs e) { try { OpenFileDialog iDialog = new OpenFileDialog(); iDialog.Title = "Select a file to import:"; iDialog.CheckFileExists = true; iDialog.Filter = "Importable Palettes|*.act;*.bmp;*.png*"; if (iDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK & iDialog.FileName != "") { if (System.IO.File.Exists(iDialog.FileName)) { string extension = Path.GetExtension(iDialog.FileName).Substring(1).ToLower(); if (extension == "png" || extension == "bmp") { Bitmap bitmap = new Bitmap(iDialog.FileName); System.Drawing.Imaging.ColorPalette palette = bitmap.Palette; if (palette.Entries.Length > 1) { Colors = new NSE_Framework.Data.GBAcolor[Math.Min(palette.Entries.Length, 256)]; } else { throw new Exception("The image loaded was not indexed or used an undefined alpha channel."); } for (int p = 0; p < Colors.Length; p++) { if (p < palette.Entries.Length) { Colors[p] = new NSE_Framework.Data.GBAcolor(palette.Entries[p]); } } DrawPalette(); if (Colors.Length == 256) { ComboBoxMode.Items.Clear(); ComboBoxMode.Items.Add("16 Color"); ComboBoxMode.Items.Add("256 Color"); ComboBoxMode.SelectedIndex = 0; } else { ComboBoxMode.Items.Clear(); ComboBoxMode.Items.Add("16 Color"); ComboBoxMode.SelectedIndex = 0; } index = 0; ButtonImport.Enabled = true; ComboBoxMode.Enabled = true; } else if (extension == "act") { FileStream stream = new FileStream(iDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(stream); byte[] b = br.ReadBytes((int)stream.Length); Colors = new NSE_Framework.Data.GBAcolor[Math.Min((b.Length - b.Length % 3) / 3, 256)]; for (int x = 0; x < Colors.Length; x++) { Colors[x] = new NSE_Framework.Data.GBAcolor(b[x * 3], b[x * 3 + 1], b[x * 3 + 2]); } DrawPalette(); index = 0; if (Colors.Length >= 256) { ComboBoxMode.Items.Clear(); ComboBoxMode.Items.Add("16 Color"); ComboBoxMode.Items.Add("256 Color"); ComboBoxMode.SelectedIndex = 0; } else { ComboBoxMode.Items.Clear(); ComboBoxMode.Items.Add("16 Color"); ComboBoxMode.SelectedIndex = 0; } ButtonImport.Enabled = true; ComboBoxMode.Enabled = true; } else { throw new Exception("The file does not exist."); } } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }