Jonathan Crispe

Jonathan Crispe

  • NA
  • 46
  • 34.4k

Picture Ediitng

Oct 15 2011 10:21 AM

any suggestion for image processing tint and noise?,

i have progress bar it in. according to our instructor, we cannot use marquee style, so any suggestion.
Thank you.



my code so far:

public partial class Form1 : Form
  {
  Image file;
  Bitmap bm_image;
 
  int i_change;
  float contrast = 0;
  public Form1()
  {
  InitializeComponent();
 
  }

  private void RB_contrast_CheckedChanged(object sender, EventArgs e)
  {
  LBL_color1.Text = "Less";
  LBL_color2.Text = "More";
  trackBar1.SetRange(0, 100);
  trackBar1.TickFrequency = 5;
 
  }

  private void RB_blackwhite_CheckedChanged(object sender, EventArgs e)
  {
  LBL_color1.Text = "Less";
  LBL_color2.Text = "More";
  trackBar1.SetRange(0, 100);
  trackBar1.TickFrequency = 5;
 
  }

  private void RB_tint_CheckedChanged(object sender, EventArgs e)
  {
  trackBar1.SetRange(0, 100);
  trackBar1.TickFrequency = 5;
  LBL_color1.Text = "Red";
  LBL_color2.Text = "Green";
  if (trackBar1.Value >= 51)
  {
  lbl_TINT.Text = "To Green:".ToString();
  }
  if (trackBar1.Value <= 49)
  {
  lbl_TINT.Text = "To Red:".ToString();
  }
  if (trackBar1.Value == 50)
  {
  lbl_TINT.Text = "".ToString();
  }
  }

  private void RB_noise_CheckedChanged(object sender, EventArgs e)
  {
  LBL_color1.Text = "Less";
  LBL_color2.Text = "More";
  trackBar1.SetRange(0, 100);
  trackBar1.TickFrequency = 5;
 
  }

  private void BTN_loadpic_Click(object sender, EventArgs e)
  {

  Stream myStream = null;
  OpenFileDialog openFileDialog1 = new OpenFileDialog();

  openFileDialog1.InitialDirectory = "c:\\";
  openFileDialog1.Filter = "Bitmap Files (*.bmp;*.dib)|*.*|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.* |PNG (*.png)|*.*|GIF (*.gif)|*.*|All files (*.*)|*.*";
 
  if (openFileDialog1.ShowDialog() == DialogResult.OK)
  {
  try
  {
  if ((myStream = openFileDialog1.OpenFile()) != null)
  {
  using (myStream)
  {
  file = Image.FromFile(openFileDialog1.FileName);
  bm_image = new Bitmap(openFileDialog1.FileName);
  pictureBox1.Image = file;
 
  }
  }
  }
  catch (Exception)
  {
  MessageBox.Show("Error: Could not read file.", "PicBender",
  MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
  }
  }

  private void trackBar1_Scroll(object sender, EventArgs e)
  {
  lbl_Tracknum.Text = trackBar1.Value.ToString();
  i_change = int.Parse(trackBar1.Value.ToString());
  }

  private void BTN_transform_Click(object sender, EventArgs e)
  {
  bm_image = new Bitmap(pictureBox1.Image);
  if (RB_contrast.Checked)
  {
  contrast = 0.04f * trackBar1.Value;

  Bitmap bm = new Bitmap(bm_image.Width, bm_image.Height);

  Graphics g = Graphics.FromImage(bm);

  ImageAttributes ia = new ImageAttributes();

  ColorMatrix cm = new ColorMatrix(new float[][]{
  new float[]{contrast, 0f, 0f, 0f, 0f,},
  new float[]{0f,contrast, 0f, 0f, 0f,},
  new float[]{0f, 0f,contrast, 0f, 0f,},
  new float[]{0f, 0f, 0f, 1f,0f},
  new float[]{0.001f,0.001f,0.001f,0f,1f}});

  ia.SetColorMatrix(cm);

  g.DrawImage(bm_image, new Rectangle(0, 0, bm_image.Width, bm_image.Height), 0, 0, bm_image.Width, bm_image.Height, GraphicsUnit.Pixel, ia);
  g.Dispose();
  ia.Dispose();
  pictureBox1.Image = bm;
  }
  if (RB_blackwhite.Checked)
  {
  for (int x = 0; x < bm_image.Width; x++)
  {
  for (int y = 0; y < bm_image.Height; y++)
  {
  //get the pixel from the original image
  Color originalColor = bm_image.GetPixel(x, y);
  //create the grayscale version of the pixel
  int newg = (int)((originalColor.A * .3) + (originalColor.G * .59)
  + (originalColor.B * .11));

  Color newColor = Color.FromArgb(newg, newg, newg);
 
  bm_image.SetPixel(x, y, newColor);
  }
  }
  pictureBox1.Image = bm_image;
  }
  if (RB_tint.Checked)
  {
  }
  if (RB_noise.Checked)
  {
  }
  }
  }


Answers (1)