已经解决。代码不是很全。篇幅原因请见谅,如果需要完整代码,可以给我留信息。 代码如下: Image im=Toolkit.getDefaultToolkit().getImage(ImageUtil.path); int iw = im.getWidth();//图片宽 int ih = im.getHeigt();//图片高 int[] pixels=new int[iw*ih];//存放像素的数组 ColorModel cm=ColorModel.getRGBdefault(); Color color = new Color(oxffffff);//要透明的颜色16进制的颜色值 for(int i=0;i<iw*ih;i++) { int red,green,blue; red = cm.getRed(pixels[i]); green = cm.getGreen(pixels[i]); blue = cm.getBlue(pixels[i]); int rgb = cm.getRGB(pixels[i]); //比较当前的像素的rgb值是否与给定颜色的rgb值相等,如果相等,则把这个颜色变透明 if(color.getRGB() == rgb){ pixels[i]=red<<16|green<<8|blue; } } //将数组中的象素产生一个图像 ImageProducer ip=new MemoryImageSource(iw,ih,pixels,0,iw); tmp=createImage(ip);//根据处理完的像素创建图像。 repaint(); //重绘图像,或者重写图像到另外一个位置
楼主【tomorrowwell】截止到2008-07-10 09:50:00的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:20 每贴平均分数:20
回帖的总数量:1 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:20
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
代码如下:
Image
im=Toolkit.getDefaultToolkit().getImage(ImageUtil.path);
int iw = im.getWidth();//图片宽
int ih = im.getHeigt();//图片高
int[]
pixels=new int[iw*ih];//存放像素的数组
ColorModel cm=ColorModel.getRGBdefault();
Color color = new Color(oxffffff);//要透明的颜色16进制的颜色值
for(int i=0;i<iw*ih;i++)
{
int red,green,blue;
red = cm.getRed(pixels[i]);
green = cm.getGreen(pixels[i]);
blue = cm.getBlue(pixels[i]);
int rgb = cm.getRGB(pixels[i]);
//比较当前的像素的rgb值是否与给定颜色的rgb值相等,如果相等,则把这个颜色变透明
if(color.getRGB() == rgb){
pixels[i]=red<<16|green<<8|blue;
}
}
//将数组中的象素产生一个图像
ImageProducer ip=new MemoryImageSource(iw,ih,pixels,0,iw);
tmp=createImage(ip);//根据处理完的像素创建图像。
repaint(); //重绘图像,或者重写图像到另外一个位置