views:

568

answers:

1

I have a BufferedImage created using

new BufferedImage(wid,hgt,BufferedImage.TYPE_INT_ARGB);

to which I assemble a wallpaper using multiple other images. It works fine in Jave SE, but when I tried to run the code on a J9 CDC/PP platform I discovered that the Personal Profile BufferedImage has no constructors!

Can anyone point me to how I can construct an alpha-channel supporting image using CDC 1.0 and Personal Profile 1.1?


Edit: For now I have created fallback code which handles NoSuchMethodError (et al.) and then simply creates an image with GraphicsConfiguration.createCompatibleImage(int,int). It might be that that creates an alpha-blending image, but it will be a few weeks before I can specifically test that due to other priorities (testing on handhelds is not my direct responsibility, so it's out of my hands).

If I find a better answer, I will post it as an answer to this; in the meantime, if someone else beats me to it, be assured I will accept your answer if it works, and the answer will be of interest to me for the foreseeable future (I expect to still need an answer in 2-5 years).

+1  A: 

The Image class (javax.microedition.lcdui.Image ) contains a method getRGB(...) which parses the Image into an array of RGB+Alpha values for each pixel in the image. Once you have the image in that format, its easy to tweak the alpha values to increase their transparency before you layer the images. This is really the only dynamic way I've seen to edit the transparency of an image in J2ME.

to get the alpha (transparency) value out of the rgba array you have to use bit-shifting like this:

int origAlpha = (rgba[j] >> 24);

and then to change the alpha (transparency) value to something different (without changing the color at that pixel), you can use bitshifting to insert a different transparency level.

int newAlpha = 0x33; // or use whatever 0-255 value you want, with 255=opaque, 0=transparent
rgba[j] = (rgba[j] & 0x00ffffff);
rgba[j] = (rgba[j] | (newAlpha << 24));

Then there is a createImage(...) method in Image that takes a byte-array of image data as a parameter, that can be used to create a new image out of your modified pixel data array.

Also helpful, SonyEricsson's developer website also has a tutorial with sample code called "Fade in and out images in MIDP 2.0" which explains "how to change the alpha value of an image to make it appear blended" which is essentially alpha-blending.

Jessica
This gives me an idea; I can try creating an image from an array of ints with every value 0xFF000000. What I need is an image where every pixel is initially transparent, because I might paint only to the outside edges, in which case I need the rest to allow the current Graphics content to show through when the image is finally painted to the Graphics context.
Software Monkey
Sorry, my question was specifically for Personal Profile (welcome to J2ME API hell). I need a java.awt.Image.
Software Monkey