java画图如何实现windows里图标的选中效果,颜色加深变蓝,透明处不变!

nil2000 2003-12-12 12:23:13
这个问题搞我好长时间,一般使用到java的RGBFilter,或者直接对色彩做alpha或其他变换,但我实现的都变为一种颜色了,原来的不见了。
最多只能给200,解决问题者,再送200。
能给出代码最好,不行给个思路。

...全文
310 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nil2000 2003-12-17
  • 打赏
  • 举报
回复
等了几天,问题还没有很好的解决,但已经有替代方法了。所以还是很感谢楼上两位。
分就一人一半吧。
wobelisk 2003-12-13
  • 打赏
  • 举报
回复
AffineTransform is not enough. It does not process Alpha or transparence 透明.

I used raster to do this.
If the image (.gif) has alpha channel, transform only pixels which alpha !=0.
If the image (.jpg) has no alpha channel, it become a little more complex. If I know the image has white( or other) background, the only transfor pixels are not white.

Process:
Image src=..... //width,height
BufferedImage proc= new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2=proc.createGraphics();
g2.drawImage(src,width,height,null); //offscreen copy src to proc

Raster rSrc=proc.getRaster();
ColorModel cm=proc.getColorModel();

float[][] matrix={ //alpha blend: src*0.75+dst*0.25, dst is a blue rect
{0.75f,0,0,0,0}, //red
{0,0.75f,0,0,0}, //green
{0,0,0.75f,0,255*0.25f}, //blue, increase blue channel
{0,0,0,0.75f,255*0.25f} //alpha
}

BandCombineOp op=new BandCombineOp(matrix, null){
// override filter to process alpha channel
public WritableRaster filter(Raster src,
WritableRaster dst){

...//src.getPixel
...//getAlpha
...//if has alpha channel and alpha!=0 use matrix to transfor
...//if no ahpha channel, and pixel color is not the background,
//do transform
.. //dst.setPixel

return dst;
}
}

WritableRaster rDst=op.filter(rSrc,rSrc); //op.filter(rSrc,null) is the same
BufferedImage dst=new BufferedImage(cm, rDst,false,null);


//draw dst to the screen if selected.

1.op.filter() refer to j2sdk source code, add the code to process alpha
2.adjust 0.75f to other numbers to get the effect you want.





nil2000 2003-12-12
  • 打赏
  • 举报
回复
谢楼上先,再顶
simonhappy 2003-12-12
  • 打赏
  • 举报
回复
试试Graphics2D中的这个类AffineTransform或者Graphics2D关联的类.
我的思路是如果前景是单色,用一些颜色的与或运算就可以了.如果是一个图片之类的东西,那么必须有一个地方可以统一处理输出前的转换,以前在AffineTransform处理过输出比例的问题,你可以看看Graphics2D其他的类.

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧