13,002,000 members (78,401 online)
Rate this:
See more:
How to read a 8-bit grayscale JPEG image using C#?
i need this code
Posted 26-Apr-11 11:51am
ngd1990315
SAKryukov 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:

Rate this:

## Solution 1

Just use `Image.FromFile`.
SAKryukov 26-Apr-11 18:21pm

Nishant, this is quite good but... You cannot be sure you're answering right question. I counted 6 variants.
--SA
Nishant Sivakumar 26-Apr-11 18:23pm

I went with the most common choice (WinForms). But yes, it's a guess on my part :-)
SAKryukov 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
Rate this:

## Solution 2

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
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

Top Experts
Last 24hrsThis month
 OriginalGriff 290 ppolymorphe 180 F-ES Sitecore 130 Bohdan Stupak 115 David_Wimbley 90
 OriginalGriff 4,857 ppolymorphe 2,437 RickZeeland 2,221 Kornfeld Eliyahu Peter 2,031 Richard Deeming 1,643