分享

J2ME图像透明化的实现

 hotbain 2010-07-24

J2ME图像透明化的实现

 
getRGB可以得到当前图片的Alpha数值,改一下就可以了。FF为不透明。00为全透明。

 

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

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的图片
 }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多