画半透明的图片

来源:互联网 发布:cad图纸打印软件 编辑:程序博客网 时间:2024/04/28 23:02

 Image image;
 int argb[]; 

    try {
      image = Image.createImage("/i.png");//导入图片
     } catch (IOException e) {
      e.printStackTrace();
     }
     argb = new int[image.getWidth()*image.getHeight()];
     image.getRGB(argb,0,image.getWidth(),0,0,image.getWidth(),image.getHeight());//获得图片的ARGB值
     int temp;
     int a= 100;//把象素的透明度都设置为100
     for(int i=0;i<argb.length;i++)
     {
      argb[i]=(a<<24) | (argb[i] & 0x00FFFFFF);// 修改最高2位的值
     }
     gBB.drawImage(image,0,0,Graphics.TOP|Graphics.LEFT);
     gBB.drawRGB(argb,0,image.getWidth(),0,100,image.getWidth(),image.getHeight(),true);//     
   

//100<<24为0x640000;