getBitmapData() incorrect size for transparent bitmaps

Hi,

getBitmapData() gives me incorrect width and height for transparent bitmaps, it seems it returns the inner bounds of the bitmap, I guess that's how LCDBitmap stores the bounds internally for optimizing drawing.

Sample code

int width, height;
playdate->graphics->getBitmapData(bitmap, &width, &height, NULL, NULL, NULL);

Thank you!

2 Likes

I have the same problem, any news on this?

Hello from almost May! Sorry for the delay, it's been a busy month. You're right, the compiler shrinks images down to the bounding box of the drawn area and tracks how much empty space it trimmed from the sides. Then when you tell it to draw at a given point it offsets that by the left and top padding values; when you ask for the image width and height it adds the left and right padding to the width and the top and bottom to the height. This is supposed to be transparent (haha) to you but there are a few places where it leaks out, like this function in the C API.

Here's my proposed fix for this, let me know what you think:

  • getBitmapData() will return the full width and height, same as if you did image:getSize() in Lua
  • If you're also getting the image data, we convert the trimmed area back to blank space so the image is identical to what went into the compiler
2 Likes

Thank you for the reply!

It looks good to me, and yes, image data should respect the returned width / height.

1 Like