Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to read a 8-bit grayscale JPEG image using C#?
i need this code
Posted
Comments
Sergey Alexandrovich Kryukov 26-Apr-11 18:22pm    
Tag the question properly and clarify! See my answer explaining why you need to clarify.
--SA
Sandeep Mewara 27-Apr-11 0:49am    
No effort.

"I need this code" => and we work for you, right? :doh:

Just use Image.FromFile.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Apr-11 18:21pm    
Nishant, this is quite good but... You cannot be sure you're answering right question. I counted 6 variants.
Please see my answer.
--SA
Nish Nishant 26-Apr-11 18:23pm    
I went with the most common choice (WinForms). But yes, it's a guess on my part :-)
Sergey Alexandrovich Kryukov 26-Apr-11 19:55pm    
Should OP choose to clarify it, we will be able to right a real thing for sure :-)
--SA
Dave Kreskowiak 27-Apr-11 13:48pm    
From the OP:

I want to read only grey pixel (8-bit)
and maybe you understand from this code :

Bitmap img1 = new Bitmap(fname1);
pictureBox1.Image = img1;
int[] myarray;
myarray = new int[256];

for (int i = 0; i< img1.Width; i++)
{
for (int j = 0; j< img1.Height; j++)
{
Color PixelColor = img1.GetPixel(i, j); (1)
int gray = (PixelColor.R + PixelColor.G + PixelColor.B) / 3; (2)


//gray = gray + 1;
myarray[gray] = myarray[gray] + 1;

}
}
in step one: i read the colored pixel by (getpixel)
in step two :i transfered the coloured pixel to grey pixel
i want to dispense on step two , and thet by getting method similarity the work of (getpixel)
but the pixel must be from the type of : bitmap and not from the type of color


and thanks for your help !
Dave Kreskowiak 27-Apr-11 13:49pm    
First, do NOT use GetPixel. It's way too slow for this.

You can find an example ofa Grayscale Filter in C# at http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx
It depends on what do you mean by "read". Do you need to access the bits in a bitmap and manipulate with this data or you just needs to draw it on screen. Also important in case you need bit data: do you need it read-only or read-write?

In both cases it also depends on what do you need to use, System.Drawing or WPF — the solutions will be quite different. Six variants, by my count. No, I'm not going to answer them all. Tag your question properly and ask exactly what do you want to do with data.

—SA
 
Share this answer
 
Comments
Member 11115090 16-Feb-15 3:15am    
how can work with the value of grayscale image i know getpixel& setpixel is for it but have the graysacle image with set pixel have 3 argument (r,g,b)
Sergey Alexandrovich Kryukov 16-Feb-15 10:11am    
Are you going to continue ignoring the questions? Please clarify what you are using, before we can discuss anything.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900