Survey: Make loaded JPEG images non-transparent?


Hello everyone!

We have a decision to make that I felt would make sense to put to a vote.

Using Assets.getBitmapData or BitmapData.fromFile (and other methods) of loading image files currently set bitmapData.transparent to true, always.

A transparent BitmapData allows transparency when you use bitmapData.draw, bitmapData.setPixel32 and bitmapData.setPixels, but is more expensive.

We support premultiplied alpha, which means we may need to go through each pixel and multiply the RGB value by the alpha before we render it. This is important for proper blending, but wholly unneeded if the image is opaque. There may be other performance boosts when a bitmapData.transparent is false.

We could set this to false when loading a JPEG, or (possibly) an opaque PNG image, but this is a breaking change if a user relies on being able to modify one of these files directly.

  • Make every loaded BitmapData transparent
  • Make every PNG transparent, and every JPEG opaque
  • Make every opaque image opaque, regardless of format
  • Do whatever Flash Player does

0 voters

Thank you for your help :smiley:


Why not have it so you can set a bool to change whether you want the image to possibly be transparent or not?


You mean, as an option within Assets.getBitmapData?

The standard Flash solution for this is:

var bitmapData2 = new BitmapData (bitmapData.width, bitmapData.height, true, 0);
bitmapData2.draw (bitmapData);

This creates a transparent copy of the BitmapData. It would look the same, but would allow further alpha-based edits


Ah okay, I didn’t know that, but yes I was thinking within Assets.getBitmapData