Norrit
Norrit

Reputation:

How to create transparent images in Java ME

How can I create an editable but transparent image in Java ME?

Upvotes: 1

Views: 1384

Answers (2)

Vijay C
Vijay C

Reputation: 4869

If you want to create the transparent image programmatically then following is the snippet.

int width = 50, height = 50;
Image  image = Image.createImage(width,height); 

int[] rgbArr = new int[width * height];

image.getRGB(rgbArr, 0, width, 0, 0, width, height);

for (int i = 0; i < rgbArr.length; i++) {

   if(rgbArr[i] == 0xFFFFFFFF){

       rgbArr[i] = 0x00000000;

   }

}

Image transImage = Image.createRGBImage(rgbArr, width, height, true);

Now you can get the graphics object on the transImage and paint whatever you want.

Upvotes: 1

L. Cornelius Dol
L. Cornelius Dol

Reputation: 64026

Use a GIF or PNG - both support transparent pixels.

Upvotes: 0

Related Questions