Is this Code Useful for you ?

Is this Posible

Is this Posible
Rack your brain 4 possibilities....

Monday, December 28, 2009

Blending Two Images ( J2ME Image )

public Image BlendImage(Image img1, Image img2, int bval) {

Image gImage = Image.createImage(img1.getWidth(), img1.getHeight());
Graphics gg = mImage.getGraphics();
gg.setColor(0xFFE3FFF);
gg.fillRect(0, 0, img1.getWidth(), img1.getHeight());

int[] ri = new int[img1.getWidth() * img1.getHeight()];
img1.getRGB(ri, 0, img1.getWidth(), 0, 0, img1.getWidth(), img1.getHeight());
Effect.blend(ri, bval);
Image temp = Image.createRGBImage(ri, img1.getWidth(), img1.getHeight(), true);
gg.drawImage(img2, 0, 0, 0);
gg.drawImage(temp, 0, 0, 0);

Graphics g1 = img1.getGraphics();
g1.drawImage(mImage, 0, 0, 0);

mImage = null;
temp = null;
System.gc();

return img1;
}




class Effect {

public static void blend(int[] r, int aVal, int mClr1, int mClr2) {
int len = r.length;
for (int i = 0; i < len; i++) {
int a = 0;
int c = (r[i] & 0x00FFFFFF);
if (mClr1 == c) {
a = 0;
} else if (mClr2 == c) {
a = 255;
} else if (alphaValue > 0) {
a = aVal;
}
a = (a << 24);
c+= a;
r[i] = c;
}
}

public static void blend(int[] r, int aVal) {
blend(raw, aVal, 0xFFFFFFFF, 0xFFFFFFFF);
}


}

// Enjoy with Images !!!!!

No comments:

Post a Comment