Click here to Skip to main content
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 12:51pm
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  

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

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2014
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