PixelFormats

  • 14 years ago

       There is something I don't understand about Microsoft.  Take a look at the PixelFormat enumeration.  Now I can understand why there are several "Reserved" formats (some super-secret GDI+ magic perhaps).  But I don't understand why there are formats like 48bppRgb, 64bppArgb, or 64bppPArgb.  If you open an image as one of these PixelFormats, it looks fine on a PictureBox.  But the BMP encoder (and I assume the other encoders) absolutely mangles it when you try and save it (there are a bunch of vertical scan lines and the colors get shifted).

       Also, when you draw on an image in one of these formats, weird things happen.  I've noticed:  when you draw a line with Width = 1 and SmoothingMode = SmoothingMode.None at a certain angle, parts of the image around the line go crazy.  But only at certain line angles and those line/Graphics settings.  When drawing a rectangle with the same settings (and those setting only), sometimes it draws the rectangle but then draws white lines extending beyond it.  Nothing happens when drawing an ellipse.  Why?

       The "smaller" formats are fine though (16bppRgb565 and 16bppRgb555).  The graphics object even uses advanced feathering techniques to approximate a color that that format can't display.

       When you try to create a Graphics object using Graphics.FromImage(Bitmap) on a 16bppArgb1555 or 16bppGrayScale Bitmap you get an "Out of memory" exception.  Why can't GDI+ make a 16bppGrayScale kind of like the other 16bpp formats and just convert colors into gray scale when using .DrawLine, .DrawRectangle, etc?  It converts invalid colors into "feathered" colors for 16bppRgb565 and 16bppRgb555...

       Whenever you try to create a Graphics object from an Indexed format (1bppIndexed, 4bppIndexed, 8bppIndexed, Indexed) you get an exception that says "A Graphics object cannot be created from an image that has an indexed pixel format."  Why not?  Can't it just do like it does for 16bpp formats and find the closest valid color for invalid colors?

       I'm not even going to mention the PixelFormat.DontCare or .Undefined formats...  Or the fact that PixelFormat.Max ("The maximum value for this enumeration.") equals 15 while 24bppRgb (the standard format) equals 137224.

       So my question is, why the inconsistency?  It just doesn't make sense...  Why provide formats that you can't do anything/much with?

       That was my rant on the PixelFormat Enumeration, next week, don't miss "Other misc. GDI+ annoyances"...  Exclamation [:)]

















  • 14 years ago

    Allright, here is an answer for all 19 of you who have viewed this Topic Exclamation [:)]:

    Bob Powell [MVP] (VIP)
    All of the 16 bit image formats in GDI+ are broken. I think that the story
    is that they were included more or less by mistake and should never have
    seen the light of day.

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

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

    The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
    Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
    Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml




















  • 14 years ago

    And here is MSDN stating that they just don't support the other Formats that I talked about:
    From:  Graphics.FromImage

    Remarks

    If the image has an indexed pixel format, this method throws an exception with the message, "A Graphics object cannot be created from an image that has an indexed pixel format." The indexed pixel formats are shown in the following list.

    • PixelFormat.Format1bppIndexed
    • PixelFormat.Format4bppIndexed
    • PixelFormat.Format8bppIndexed

    This method also throws an exception if the image has any of the following pixel formats.

    • PixelFormat.Undefined
    • PixelFormat.DontCare
    • PixelFormat.Format16bppArgb1555
    • PixelFormat.Format16bppGrayScale





Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius