This project is read-only.

GDIPLusX: possible GetBounds Serious BUG

Topics: General
Nov 19, 2007 at 7:12 PM
Edited Nov 19, 2007 at 7:14 PM
I have found a problem when using GetBounds() to get a Rect and then using that Rect in a call to LockBits. LockBits just fails silently, and Stride, Height, Width, Scan0, are all zero.

Code to repro:

      • GetBounds makes LockBits fail
      • maybe because GetBounds returns a xfcRectangleF and not a xfcRectangle???


With _Screen.System.Drawing

m.loBitmap =.Bitmap.New(128, 128, 0, .Imaging.PixelFormat.Format32bppARGB)

*** Create a rectangle the size of the bitmap
m.loRect = .Rectangle.New(0, 0, 128, 128)
?m.loRect.Left, m.loRect.Top, m.loRect.Width, m.loRect.Height

*** LockBits fails with GetBounds, comment the following line to make code work:
m.loRect = m.loBitmap.GetBounds()
?m.loRect.Left, m.loRect.Top, m.loRect.Width, m.loRect.Height

*** Lock the bits of the bitmap
m.loBitmapData = m.loBitmap.LockBits(m.loRect, .Imaging.ImageLockMode.Readwrite, .Imaging.PixelFormat.Format32bppARGB)

*** The size of the pixeldata has to be calculated using the stride
m.lnSize = m.loBitmapData.Stride * m.loBitmapData.Height

?"m.lnSize", m.lnSize, m.loBitmapData.Stride, m.loBitmapData.Height, m.loBitmapData.Width, m.loBitmapData.Scan0


Just comment the line "m.loRect = m.loBitmap.GetBounds()" to make it work
Nov 19, 2007 at 8:27 PM
Thanks, I'll check this out, and see what can be done there.
Nov 21, 2007 at 7:32 AM

Found the problem #$@#%&!!!!!!

Image.GetBounds Method returns a System.Drawing.RectangleF

And Bitmap..LockBits Method requires a System.Drawing.Rectangle

RectangleF NOT EQUAL TO Rectangle !!

There seems to be a RectangleConverter class:

But not clear how to use it.

For now beware about this! Use Rectangle and RectangleF where appropiate

I solved it for now doing this:

m.loRect = _Screen.System.Drawing.Rectangle.Ceiling(m.loBitmap32.GetBounds())

Guess the RectangleConverter class must be used somehow, but there is no RectangleConverter class in GDIPlusX

Or maybe the name is just to confuse, and it has nothing to do with RectangleF conversion to Rectangle talks about converting strings?????

Lost in the .Net Classes maze...

Nov 26, 2007 at 11:05 PM
Edited Nov 26, 2007 at 11:06 PM
Thanks for tracking this down. We will address this under work item: GDIPlusX: Feature Request: type checking for rectangles