J2ME圖像透明化的實現(xiàn)getRGB可以得到當前圖片的Alpha數(shù)值,改一下就可以了。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()]; // 將源圖的像素數(shù)據(jù)存儲在array數(shù)組中 image.getRGB(array,0,image.getWidth(),0,0,image.getWidth(),image.getHeight()); // 生成新的圖片像素數(shù)據(jù) 更改array數(shù)組中的數(shù)據(jù)
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的圖片 } } |
|