Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

16bppGrayScale

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bern11 - 01 Mar 2008 20:44 GMT
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
Bob Powell [MVP] - 01 Mar 2008 20:49 GMT
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
Peter Duniho - 02 Mar 2008 01:01 GMT
>       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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.