private void BtnSave_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); if (dialog.ShowDialog() != DialogResult.OK) { return; } List <Color> colors = PalettePictureBox.ExtractColors(); byte[] rgbaArray = new byte[4 * colors.Count]; int ptr = 0; foreach (Color color in colors) { rgbaArray[ptr++] = color.R; rgbaArray[ptr++] = color.G; rgbaArray[ptr++] = color.B; rgbaArray[ptr++] = color.A; } File.WriteAllBytes(dialog.FileName, rgbaArray); MessageBox.Show(colors.Count + " colors saved to binary file " + dialog.FileName, "File saved", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void BtnExtract_Click(object sender, EventArgs e) { List <Color> colors = PalettePictureBox.ExtractColors(); StringBuilder data = new StringBuilder(); data.Append("Colors extracted: " + colors.Count + Environment.NewLine + Environment.NewLine); foreach (Color color in colors) { data.Append(TxtPrefix.Text); if (CmbFormat.SelectedIndex == 0) { data.Append(ToHexRgba(color)); } else if (CmbFormat.SelectedIndex == 1) { data.Append(ToHexArgb(color)); } data.Append(TxtSuffix.Text + Environment.NewLine); } TxtData.Text = data.ToString(); }
private void BtnSaveGimp_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); if (dialog.ShowDialog() != DialogResult.OK) { return; } List <Color> colors = PalettePictureBox.ExtractColors(); FileInfo fi = new FileInfo(dialog.FileName); string file = "GIMP Palette\nName: " + fi.Name + "\n#\n"; foreach (Color color in colors) { file += color.R.ToString().PadLeft(3) + " " + color.G.ToString().PadLeft(3) + " " + color.B.ToString().PadLeft(3) + "\n"; } File.WriteAllText(dialog.FileName, file); MessageBox.Show(colors.Count + " colors saved to GIMP palette file " + dialog.FileName, "File saved", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public MainWindow() { InitializeComponent(); TxtOffsetX.Text = PalettePictureBox.GetOffsetX().ToString(); TxtOffsetY.Text = PalettePictureBox.GetOffsetY().ToString(); TxtGapX.Text = PalettePictureBox.GetGapX().ToString(); TxtGapY.Text = PalettePictureBox.GetGapX().ToString(); CmbFormat.SelectedIndex = 0; }
private void SetupTextChanged(object sender, EventArgs e) { try { PalettePictureBox.SetOffsetX(int.Parse(TxtOffsetX.Text)); PalettePictureBox.SetOffsetY(int.Parse(TxtOffsetY.Text)); PalettePictureBox.SetGapX(int.Parse(TxtGapX.Text)); PalettePictureBox.SetGapY(int.Parse(TxtGapY.Text)); PalettePictureBox.Refresh(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }