Search code examples
image-processingcoronasdkalpha-transparency

Can I determine the average transparency of an image in Corona SDK?


Using Corona SDK, I want to be able to determine if a sprite frame is blank and if so disregard it.

In my workflow, I'm using a perl script to automatically create a bunch of equally-sized, square, image/sprite sheets from multiple individual images (using the 'montage' command-line tool from ImageMagick).

Obviously, depending on the original image dimensions, the final few frames of the final image sheet may be blank/transparent (in other words if I generate a bunch of image sheets each with 4 x 5 frames and I originally have 57 images, I will have 2 image sheets of 20 frames each and my final image sheet will have 17 frames with 3 blank frames in its final row).

I don't want the code in my Corona app to be dependent on the number of images/frames, etc. so I want my code to treat each of my image sheets the same (I'm creating an animation that spans multiple image/sprite sheets). Obviously I don't want to display a couple of blank frames in my animation, so my question is can I process each frame in real time to determine its transparency, or otherwise do some sort of pixel analysis to see if I need to disregard the frame?

Maybe I made this sound more complicated than it actually is...


Update

Ok, simpler question: is it possible to access the pixel data of an image in Corona to get the alpha values?



Solution

  • Corona SDK does not give you access to pixel level data, so the answer to both questions is No, you cannot. This is a very frequently asked for feature, but the way Corona SDK uses the OpenGL layer, it makes getting this information very difficult.