using System; using System.Drawing; using System.Windows.Forms; using System.Drawing.Imaging; public class FormMain : Form { [STAThread] static void Main() { Application.Run(new FormMain()); } Button button_read=new Button(), button_thicker = new Button(), button_write = new Button(); Button button_thinner = new Button(); Button bfit = new Button(); TextBox torig = new TextBox(), tbase = new TextBox(), ttobe = new TextBox(); TextBox tpix = new TextBox(); PictureBox pbox=new PictureBox(); Bitmap bm, bmmodif, bmout; int limitw=0, limite=0, limitn=0, limits=0, visiw=0, visih=0; public FormMain() { int y1 = 2, y2=27; this.Size = new Size(900, 760); // button_read.SetBounds(10, y1, 80, 20); button_read.Text = "ファイル読込"; button_read.Click += (o, e) => { OpenFileDialog dialog = new OpenFileDialog(); if(dialog.ShowDialog() == DialogResult.OK) { bm = new Bitmap(Image.FromFile(dialog.FileName)); bmmodif = new Bitmap(Image.FromFile(dialog.FileName)); pbox.Image = bmmodif; limite = bm.Width; limits = bm.Height; torig.Text = limite.ToString() + ", " + limits.ToString(); visiw = 400; visih = 300; ttobe.Text = visiw.ToString() + ", " + visih.ToString(); limitw = limitn = 0; tbase.Text = "0, 0"; Refresh(); } }; Controls.Add(button_read); // button_thinner.SetBounds(110, y1, 80, 20); button_thinner.Text = "薄くする"; button_thinner.Click += (o, e) => { for (int j=0; j { for (int j=0; j { bmout = new Bitmap(limite-limitw, limits-limitn); for (int i=0; i { ttobe.Text = torig.Text; tbase.Text = "0, 0"; }; // { int x1 = 410; Label label = new Label(); label.Text = "NWpoint(x, y)"; label.SetBounds(x1, y2-15, 80, 15); Controls.Add(label); tbase.SetBounds(x1, y2, 75, 20); Controls.Add(tbase); } // { int x1 = 500; Label label = new Label(); label.Text = "trim size(w, h)"; label.SetBounds(x1,y2-15, 80, 15); Controls.Add(label); ttobe.SetBounds(x1, y2, 75, 20); Controls.Add(ttobe); } tbase.TextChanged += (o, e) => { try{ int c = tbase.Text.IndexOf(","); int x = int.Parse(tbase.Text.Substring(0, c)); int y = int.Parse(tbase.Text.Substring(c + 1)); limitw = x; limite = limitw + visiw; limitn = y; limits = limitn + visih; doshadow(); Refresh(); } catch { } }; ttobe.TextChanged += (o, e) => { try{ int c = ttobe.Text.IndexOf(","); int x = int.Parse(ttobe.Text.Substring(0, c)); int y = int.Parse(ttobe.Text.Substring(c + 1)); visiw = x; limite = limitw + visiw; visih = y; limits = limitn + visih; doshadow(); Refresh(); } catch { } }; { int x1 = 610; Label label = new Label(); label.Text = "color"; label.SetBounds(x1, y2-15, 100, 15); Controls.Add(label); tpix.SetBounds(x1, y2, 95, 20); tpix.Enabled = false; Controls.Add(tpix); } // int origx = 10, origy = 50; pbox.SetBounds(origx, origy, 1280, 950); Controls.Add(pbox); pbox.MouseMove += (o, e) => { int xwas = xsample; int x = e.X, y = e.Y; if (bm == null || x<10 || y<10 || x>=bm.Width || y >= bm.Height) { xsample = -1; ysample = -1; if (xwas >= 0) { doshadow(); Refresh(); } return; } int huh = 1; xsample = x; ysample = y; Color pixel = bm.GetPixel(x, y); int r = pixel.R, g = pixel.G, b = pixel.B; string str = r.ToString() + ", " + g.ToString() + ", " + b.ToString(); tpix.Text = str; doshadow(); Refresh(); }; pbox.MouseLeave += (o, e) => { xsample = -1; ysample = -1; doshadow(); Refresh(); }; } // ======================================================================== int xsample=-1, ysample = -1; void doshadow() { if (bm==null) { return; } for (int i=0; i5) || (j == j0 && Math.Abs(i-i0)>5)) { Color pnew = Color.FromArgb(0, 0, 0); bmmodif.SetPixel(i, j, pnew); } else if (i < limitw || j < limitn || i >= limite || j >= limits) { Color pnew = Color.FromArgb(pixel.R/4, pixel.G/4, pixel.B/4); bmmodif.SetPixel(i, j, pnew); } else { Color pnew = Color.FromArgb(pixel.R, pixel.G, pixel.B); bmmodif.SetPixel(i, j, pnew); } } if (limite <= bm.Width && limits <= bm.Height) { button_write.Enabled = true; } else { button_write.Enabled = false; } } } // ======================================================================= int thin(int ref0) { int toret = 255 - (255 - ref0) / 2; return toret; } // ======================================================================== int func(int ref0) { int toret = ref0 - 50; if (ref0 < 100) { toret = ref0 / 2; } else if (ref0 >= 205) { toret = 255 - (255 - ref0) * 2; } return toret; } // ======================================================================== } // ######################## PictureTrimmer.cs end #############################