J2ME图像透明化的实现getRGB可以得到当前图片的Alpha数值,改一下就可以了。FF为不透明。00为全透明。
import javax.microedition.lcdui.Image; public class MyRgb extends Canvas {
Image image; int[] array; public MyRgb(){ try{ image=Image.createImage("/logo.png"); }catch(Exception e){ e.printStackTrace(); } array=new int[image.getWidth()*image.getHeight()]; // 将源图的像素数据存储在array数组中 image.getRGB(array,0,image.getWidth(),0,0,image.getWidth(),image.getHeight()); // 生成新的图片像素数据 更改array数组中的数据
for(int i=0;i<array.length;i++){ array[i]&=0xbbffffff;// 更改透明度 } } public void paint(Graphics g){ g.setColor(255,0,255); g.fillRect(0,0,getWidth(),getHeight()); g.drawRGB(array,0,image.getWidth(),0,0,image.getWidth(),image.getHeight(),true);//画出改变过ALPHA的图片 } } |
|