Groups | Blog | Home
all groups > dotnet drawing api > june 2005 >

dotnet drawing api : Using Bitmap class GetPixel and SetPixel in Format8bppIndexed pixel format


Steve
6/19/2005 12:00:00 AM
Hi

I am new to MSVS.NET and GDI and I am attempting to create a VC++ .NET
Windows Forms App that will produce and display a bitmap.

Using the default pixel format was pretty straightforward but really I would
like the bitmap in colour indexed format for image processing use and would
like to use Format8bppIndexed or perhaps later Format4bppIndexed formats.

Trouble is SetPixel now causes an exception:

"
An unhandled exception of type 'System.Exception' occurred in
system.drawing.dll
Additional information: SetPixel is not supported for images with indexed
pixel formats.
"

At least this is an informative error.

I would be grateful if somebody could suggest a suitable alternative
approach for GETting and SETting pixels in colour indexed pixel format
bitmaps.

Cheers
Steve

Garry Freemyer
6/19/2005 10:39:46 AM
Perhaps you can copy it to another bitmap and change the format to unindexed
along the way and then maybe
you could change the format of the copy?

[quoted text, click to view]

Steve
6/19/2005 5:51:57 PM

[quoted text, click to view]

Dont think this would give me the read/write access to the colour index
bitmap that Im looking for -- unless Ive misunderstood your suggestion. If
so can you explain a little further for me.

Cheers
Steve


[quoted text, click to view]

Steve
6/19/2005 9:23:51 PM
Cool -- that works a treat, many thanks Bob.

Out of interest I needed the following C++ syntax for the read.write pixel
buffer pointer extraction:

unsigned char * pixel_buffer = (unsigned char *)
pixMapData->Scan0.ToInt32();

The example C++ code syntax did not build -- probably due to the fact that I
used the .NET Windows Form wizard or something.

Useful website, I think I will be referring to it quite often from now.

Cheers
Steve

[quoted text, click to view]

Bob Powell [MVP]
6/19/2005 9:25:40 PM
The GDI+ FAQ has details of the LockBits method and it's usage.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

Etienne Boucher
6/20/2005 5:55:35 PM
[quoted text, click to view]

You might want to use byte*, remember that char is 16bit in .NET.

Etienne Boucher

Steve
6/21/2005 12:00:00 AM

[quoted text, click to view]

Ouch good catch -- although Im a little confused now cause it worked as
8-bit okay.

[quoted text, click to view]

AddThis Social Bookmark Button