None of the 16 bit encoders for GDI+ work. This is a long standing and well
known problem.

Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
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.
> Anyone know how to create a 16bppGrayScale? The following code
> crashes at the save statement with an OutOfMemory exception:
[quoted text clipped - 6 lines]
> snipet to test creating a GrayScale bitmap. I was expecting it to save a
> blank or random-noise bitmap
> Anyone know how to create a 16bppGrayScale? The following code
> crashes at the save statement with an OutOfMemory exception:
[quoted text clipped - 6 lines]
> test snipet to test creating a GrayScale bitmap. I was expecting it to
> save a blank or random-noise bitmap
Unfortuantely, .NET's support for various pixel formats, well...it sucks.
Not only does .NET not support that format and many others when creating
new Bitmap instances from scratch, the documentation doesn't bother to
mention this in a clear way, and .NET doesn't throw a useful exception
that would immediately alert you to the fact.
If you do a search on MSDN or Google using the term
"PixelFormat.Format16bppGrayScale" or even just "Format16bppGrayScale"
you'll find lots of other people who've run into the same problem you have.
I like .NET, a lot. But this is one glaring area where Microsoft really
has just screwed up big time. Even if there was a good reason for them
having this lame support of bitmap formats, there's absolutely no excuse
for it not being better-documented and there not being better errors when
you try. Sorry you ran into the issue.
Pete
bern11 - 02 Mar 2008 01:51 GMT
I had seen some references to formats not working, but I did get
these 16 bit formats to work: Format16bppArgb1555, Format16bppRgb555,
Format16bppRgb565 with an idiot-simple clone statement such as:
bmpTemp = bmpBuffer.Clone(new Rectangle(0, 0, bmpBuffer.Width,
bmpBuffer.Height), PixelFormat.Format16bppArgb1555);
I can't get the indexed formats to work though...
>> Anyone know how to create a 16bppGrayScale? The following code
>> crashes at the save statement with an OutOfMemory exception:
[quoted text clipped - 24 lines]
>
> Pete
Peter Duniho - 02 Mar 2008 02:10 GMT
> I had seen some references to formats not working, but I did get
> these 16 bit formats to work: Format16bppArgb1555, Format16bppRgb555,
[quoted text clipped - 4 lines]
>
> I can't get the indexed formats to work though...
Well, you're better off than I am. I couldn't even get all of those
formats to work via cloning. :( Rgb555 and Rgb565 worked, but the
Argb1555 threw the same out-of-memory exception I get with other
unsupported formats. And the formats that work with cloning, they work
fine just creating a bitmap from scratch too (i.e. the cloning is a red
herring).
Pete