set Alpha To Image micro edition - Java javax.microedition.lcdui

Java examples for javax.microedition.lcdui:Graphics

Description

set Alpha To Image micro edition

Demo Code


import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Main{
    public static Image setAlphaToImage(Image sourceImage, int prcAlpha) {
        int imageWidth = sourceImage.getWidth();
        int imageHeight = sourceImage.getHeight();
        int[] rgbData = new int[imageWidth * imageHeight];
        sourceImage.getRGB(rgbData, 0, imageWidth, 0, 0, imageWidth,
                imageHeight);//from  w ww  .  j ava 2  s . c o  m
        int a, r, g, b;
        int currPoint;
        for (int y = 0; y < imageHeight * imageWidth; y++) {
            currPoint = rgbData[y];
            a = currPoint & 0xff000000;
            r = currPoint & 0xff;
            g = currPoint & 0xff00;
            b = currPoint & 0xff0000;
            if (a == 0xff000000) {
                a = 256;
            } else {
                a >>= 24;
            }
            a -= (255 * prcAlpha) / 100;
            if (a >= 256) {
                a = 0xff000000;
            } else {
                a <<= 24;
            }
            rgbData[y] = a | r | g | b;
        }
        return Image.createRGBImage(rgbData, imageWidth, imageHeight, true);
    }
}

Related Tutorials