Community discussion forum

Analyse the picture and produce control

  • 9 months ago
    Hello Friends, I have a small problem in processing image. My project is to get a certain amount of pixels and according to the color, i have to produce a control and display the selected pixels. Since i am new to the technology, i have some problem of using getpixel() and setpixel() functions, i searched for the net for more codes but its not working on my system. The code i written is using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Bitmap image1; private void button1_Click(object sender, EventArgs e) { try { // Retrieve the image. image1 = new Bitmap(@"C:\picture2.bmp", true); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < image1.Width; x++) { for (y = 0; y < image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); //Color newColor = Color.FromArgb(234,456,765); image1.SetPixel(x, y, Color.FromArgb(255,(Int32)(0.5 * pixelColor.R + 0.3 * pixelColor.G + 0.2 * pixelColor.B), (Int32)(pixelColor.R + 0.3 * pixelColor.G + 0.2 * pixelColor.B), (Int32)(pixelColor.R + 0.3 * pixelColor.G + 0.2 * pixelColor.B))); } } this.Invalidate(); // Set the PictureBox to display the image. pictureBox1.Image = image1; // Display the pixel format in Label1. label1.Text = "Pixel format: " + image1.PixelFormat.ToString(); } catch (ArgumentException) { MessageBox.Show("There was an error." + "Check the path to the image file."); } } this code is correct but its not displaying the image for the algorithm i wrote in color.Fromargb(). when i run this program it shows the exception i wrote in catch block. In the function argument fromargb(), what ever the integer values i give otherthan the algotrithm also it goes to the catch block. But the file path i gave is correct.When i give simple arguments to Fromargb(pixelcolor.R,0,0) it showing the picture. Please help me in solving the problem r else tell me do i use the fromargb() function wrongly. Anyone please help me.......
    Post was edited on 15/02/2009 11:20:28 Report abuse

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!