Click here to Skip to main content
11,712,727 members (78,250 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How to read a 8-bit grayscale JPEG image using C#?
i need this code
Posted 26-Apr-11 11:51am
ngd1990315
Comments
SAKryukov at 26-Apr-11 18:22pm
   
Tag the question properly and clarify! See my answer explaining why you need to clarify.
--SA
Sandeep Mewara at 27-Apr-11 0:49am
   
No effort.

"I need this code" => and we work for you, right? :doh:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just use Image.FromFile.
  Permalink  
Comments
SAKryukov at 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
Nishant Sivakumar at 26-Apr-11 18:23pm
   
I went with the most common choice (WinForms). But yes, it's a guess on my part :-)
SAKryukov at 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 at 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 at 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: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
Comments
Member 11115090 at 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 at 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)

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 300
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 300
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100