blend Color And Image micro edition - Java javax.microedition.lcdui

Java examples for javax.microedition.lcdui:Graphics

Description

blend Color And Image micro edition

Demo Code


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

public class Main{
    /** Primary colors **/
    private static int pRed__ = 0;
    private static int pGreen = 0;
    private static int pBlue_ = 0;
    public static Image blendColorAndImage(Image sourceImage, int blendColor) {
        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 w  w.  ja va  2  s .com*/
        int r, g, b;
        pRed__ = (blendColor & 0x0000ff);
        pGreen = (blendColor & 0x00ff00) >> 8;
        pBlue_ = (blendColor & 0xff0000) >> 16;
        int currPoint;
        for (int y = 0; y < imageHeight * imageWidth; y++) {
            currPoint = rgbData[y];
            r = currPoint & 0x0000ff;
            g = (currPoint & 0x00ff00) >> 8;
            b = (currPoint & 0xff0000) >> 16;

            r = ((r + pRed__) / 2);
            g = ((g + pGreen) / 2);
            b = ((b + pBlue_) / 2);

            rgbData[y] = r | g << 8 | b << 16;
        }
        return Image
                .createRGBImage(rgbData, imageWidth, imageHeight, false);
    }
}

Related Tutorials