This is a discussion on Converting image from one format to another in C# within the C# Programming forums, part of the Software Development category; Hi Sathish, Thanks.This code seems to be very simple and perfect.I would say that this is apt to ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, You can use the following code to convert the image to gray-scale image Code: public bool GrayScale(Bitmap b)
{
// GDI+ still lies to us - the return format is BGR, NOT RGB.
BitmapData bmData = b.LockBits(new Rectangle(0,0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride; //the length of the line
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte * p = (byte*)(void*)Scan0;
int nOffset = stride - b.Width*3;
byte red, green, blue;
for(int y=0;y < b.Height;++y)
{
for(int x=0; x < b.Width; ++x )
{
blue = p[0];
green = p[1];
red = p[2];
p[0] = p[1] = p[2] = (byte)(.299 * red
+ .587 * green
+ .114 * blue);
p += 3;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/c-programming/5233-converting-image-one-format-another-c.html | |||
| Posted By | For | Type | Date |
| DiscussWeb IT Community - Technical Support and Technology Discussions | This thread | Refback | 02-12-2008 09:41 PM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert image to other image format using CODEC in .NET 3.0 | Mramesh | C# Programming | 0 | 02-07-2008 02:33 AM |
| Converting a generics List<T> to string[] | oxygen | C# Programming | 4 | 12-21-2007 02:34 AM |
| How to convert jpg, bmp, tif,... image formats in to another format using c# .Net? | Archer | C# Programming | 1 | 09-07-2007 07:23 AM |
| Converting Nikon camera RAW images to JPEG,TIFF files using Adobe dll in C#.NET | oxygen | C# Programming | 5 | 08-16-2007 02:26 AM |
| Better Image Format | Joe | Web Design Help | 12 | 03-06-2007 10:31 PM |