private void ChangePixelSize(object sender, EventArgs e) { String value = Properties.Settings.Default.PixelSize.ToString(); if (InputBox("PixelPaint | " + GetLang("Pixel_Size_Menu_Item"), GetLang("Image_Reset_Warning"), ref value).Equals(DialogResult.OK)) { if (int.Parse(value) < 5) { MessageBox.Show(GetLang("Min_Pixel_Size_Error"), GetLang("Error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Properties.Settings.Default.PixelSize = int.Parse(value); Properties.Settings.Default.Save(); this.s = int.Parse(value); Thread thread = new Thread(() => { this.Invoke(new System.Action(() => { this.Text = MainForm.GetLang("Unnamed_Title"); })); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Clear(); })); px = 0; int x = 0; int y = 0; int s = this.s; while (y + s <= ImagePanel.Height) { while (x + s <= ImagePanel.Width) { PictureBox box = new PictureBox(); box.Name = "Box" + px; box.Click += new EventHandler(Paint); box.Size = new Size(s, s); box.BackColor = Color.White; box.BorderStyle = BorderStyle.FixedSingle; box.Location = new Point(x, y); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Add((Control)box); })); x += s; px += 1; PixelSizeLabel.Invoke(new System.Action(() => { PixelSizeLabel.Text = px.ToString(); })); } x = 0; y += s; } }); this.threads.Add(thread); MainForm.threads.Add(thread); thread.Start(); this.fileName = ""; } }
public static int[] UpdateImagePanel(ImagePanel imagePabelControl, Image Image2Show, bool NormalizeImage = false) { int[] retval = new int[2]; retval[0] = 0; retval[1] = 0; int[] nullretval = new int[2]; retval[0] = 0; retval[1] = 0; if (imagePabelControl.InvokeRequired) { UpdateImagePanelCallback d = UpdateImagePanel; imagePabelControl.Invoke(d, new object[] { imagePabelControl, Image2Show, NormalizeImage }); } else { if (Image2Show == null) { imagePabelControl.Image = null; return(nullretval); } if (NormalizeImage) { int th_width = imagePabelControl.Width; int th_height = (int)(Math.Round(((double)th_width / (double)Image2Show.Width) * (double)Image2Show.Height, 0)); if (th_height > imagePabelControl.Height) { th_height = imagePabelControl.Height; th_width = (int)Math.Round((double)th_height * (double)Image2Show.Width / (double)Image2Show.Height); } imagePabelControl.Image = (Bitmap)Image2Show.GetThumbnailImage(th_width, th_height, null, IntPtr.Zero); retval[0] = th_width; retval[1] = th_height; } else { imagePabelControl.Image = (Bitmap)Image2Show; retval[0] = Image2Show.Width; retval[1] = Image2Show.Height; } } return(retval); }
private void ResetPixels(object sender, EventArgs e) { if (MessageBox.Show(GetLang("Image_Reset_Warning"), "PixelPaint | " + GetLang("Reset_Confirmation"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning).Equals(DialogResult.OK)) { Thread thread = new Thread(() => { this.Invoke(new System.Action(() => { this.Text = MainForm.GetLang("Unnamed_Title"); })); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Clear(); })); px = 0; int x = 0; int y = 0; int s = this.s; while (y + s <= ImagePanel.Height) { while (x + s <= ImagePanel.Width) { PictureBox box = new PictureBox(); box.Name = "Box" + px; box.Click += new EventHandler(Paint); box.Size = new Size(s, s); box.BackColor = Color.White; box.BorderStyle = BorderStyle.FixedSingle; box.Location = new Point(x, y); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Add((Control)box); })); x += s; px += 1; PixelSizeLabel.Invoke(new System.Action(() => { PixelSizeLabel.Text = px.ToString(); })); } x = 0; y += s; } }); this.threads.Add(thread); MainForm.threads.Add(thread); thread.Start(); this.fileName = ""; } }
public void NewProjekt() { Thread thread = new Thread(() => { this.Invoke(new System.Action(() => { this.Text = MainForm.GetLang("Unnamed_Title"); })); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Clear(); })); px = 0; int x = 0; int y = 0; int s = this.s; while (y + s <= ImagePanel.Height) { while (x + s <= ImagePanel.Width) { PictureBox box = new PictureBox(); box.Name = "Box" + px; box.Click += new EventHandler(Paint); box.Size = new Size(s, s); box.BackColor = Color.White; box.BorderStyle = BorderStyle.FixedSingle; box.Location = new Point(x, y); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Add(box); })); x += s; px += 1; PixelSizeLabel.Invoke(new System.Action(() => { PixelSizeLabel.Text = px.ToString(); })); } x = 0; y += s; } }); this.threads.Add(thread); MainForm.threads.Add(thread); thread.Start(); }
public void Open(String fileName) { Thread thread = new Thread(() => { if (File.Exists(fileName)) { this.Invoke(new System.Action(() => { this.Text = fileName.Substring(fileName.LastIndexOf("\\") + 1).Replace(".pxp", ""); })); StreamReader reader = new StreamReader(File.OpenRead(fileName)); String content = reader.ReadToEnd(); string[] result = content.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); Properties.Settings.Default.PixelSize = int.Parse(result[0].Split('=')[1]); Properties.Settings.Default.Save(); this.Invoke(new System.Action(() => { this.Text = fileName; })); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Clear(); })); px = 0; int x = 0; int y = 0; int s = int.Parse(result[0].Split('=')[1]); while (y + s <= ImagePanel.Height) { while (x + s <= ImagePanel.Width) { PictureBox box = new PictureBox(); box.Name = "Box" + px; box.Click += new EventHandler(Paint); box.Size = new Size(s, s); box.BackColor = Color.White; box.BorderStyle = BorderStyle.FixedSingle; box.Location = new Point(x, y); ImagePanel.Invoke(new System.Action(() => { ImagePanel.Controls.Add((Control)box); })); x += s; px += 1; PixelSizeLabel.Invoke(new System.Action(() => { PixelSizeLabel.Text = px.ToString(); })); } x = 0; y += s; } this.fileName = fileName; this.name = fileName.Substring(fileName.LastIndexOf("\\") + 1).Replace(".pxp", ""); result = result.Where(val => val != result[0]).ToArray(); int i = 0; while (i < result.Length) { PictureBox box = (PictureBox)ImagePanel.Controls[i]; string[] vs = result[i].Split('|'); Color color = Color.FromArgb(int.Parse(vs[0]), int.Parse(vs[1]), int.Parse(vs[2])); this.Invoke(new System.Action(() => { box.BackColor = color; })); i++; } } else { MessageBox.Show(GetLang("Path_Not_Exists"), GetLang("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }); this.threads.Add(thread); MainForm.threads.Add(thread); thread.Start(); }