J2ME圖像透明化的實(shí)現(xiàn)getRGB可以得到當(dāng)前圖片的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()]; // 將源圖的像素?cái)?shù)據(jù)存儲(chǔ)在array數(shù)組中 image.getRGB(array,0,image.getWidth(),0,0,image.getWidth(),image.getHeight()); // 生成新的圖片像素?cái)?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);//畫(huà)出改變過(guò)ALPHA的圖片 } } |
|
|
來(lái)自: hotbain > 《我的圖書(shū)館》