16bppGrayScale

  • Thread starter Thread starter bern11
  • Start date Start date
B

bern11

Anyone know how to create a 16bppGrayScale? The following code
crashes at the save statement with an OutOfMemory exception:

bmpTemp = new Bitmap(bmpBuffer.Width, bmpBuffer.Height,
PixelFormat.Format16bppGrayScale);
bmpTemp.Save(ImageSaveFileDlg.FileName);

Am I missing a pallete initialization or something? This is simply a
test snipet to test creating a GrayScale bitmap. I was expecting it to
save a blank or random-noise bitmap
 
None of the 16 bit encoders for GDI+ work. This is a long standing and well
known problem.

--
--
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:

bmpTemp = new Bitmap(bmpBuffer.Width, bmpBuffer.Height,
PixelFormat.Format16bppGrayScale);
bmpTemp.Save(ImageSaveFileDlg.FileName);

Am I missing a pallete initialization or something? This is simply a
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
 
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...
 
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...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top