GDIPlusX: Bitmap.New has problems with some parameters

Topics: Attention VFPX Admins
Developer
Nov 17, 2007 at 2:25 AM
Edited Nov 27, 2007 at 1:57 PM
This code works, using .Imaging.PixelFormat.Format24bppRGB

*!* Create new bitmap, the size of the source PNG, 24bpp
m.loBitmap =.Bitmap.New(m.loSourceBitmap.Width, m.loSourceBitmap.Height, 0, .Imaging.PixelFormat.Format24bppRGB)
m.loGraphics.Dispose()
m.loGraphics = .Null.
m.loGraphics = .Graphics.FromImage(m.loBitmap)
*!* Clear the new bitmap with white
m.loGraphics.Clear(.Color.White)
This code does not work, using .Imaging.PixelFormat.Format16bppGrayScale

*!* Create new bitmap, the size of the source PNG, 24bpp
m.loBitmap =.Bitmap.New(m.loSourceBitmap.Width, m.loSourceBitmap.Height, 0, .Imaging.PixelFormat.Format16bppGrayScale)
m.loGraphics.Dispose()
m.loGraphics = .Null.
m.loGraphics = .Graphics.FromImage(m.loBitmap)
*!* Clear the new bitmap with white
m.loGraphics.Clear(.Color.White)
I get an error "LOGRAPHICS is not an Object" at the last line. I have tried other formats, some work, some don´t.

Carlos Alloatti
Nov 19, 2007 at 10:20 AM
Hi Carlos,

The GDI+ Graphics class does not allow drawing in Indexed Images. I mean, 1bpp, 4bpp and 16bpp images are allowed just to be loaded, but not to become a drawing surface.

GdiPlus.dll allows drawing only on 24bpp and 32bpp images.
More info and reliable workarounds can be obtained here.
http://weblogs.foxite.com/cesarchalom/archive/2006/03/18/1302.aspx

This is not a bug, it's by design from GdiPlus.dll.
IMO, in the future versions of GdiPlus.dll, this possibility may be added.

Unfortunately, there's nothing we can do on this matter.
Developer
Nov 19, 2007 at 1:57 PM
Thank you Cesar.
Developer
Nov 26, 2007 at 10:37 PM
Edited Nov 26, 2007 at 10:48 PM

PS: I love it how a site dedicated to CODE (CodePlex) screws up the code I write. Do I have to put {] on every line???


You can wrap code up in double curly braces to preserve your code format. See: Markup Guide

Sample:
{{
IF Code <> Formatted
   UseMarkup( )
ENDIF
} }


Renders:
IF Code <> Formatted
   UseMarkup( )
ENDIF
Developer
Nov 27, 2007 at 2:00 PM
Thanks for the tip, I have edited the original post.

I noticed that if you want a blank line before and after the code block, you must have a blank line before the opening curly braces, but you don't need a blank line after the closing curly braces...