随笔 - 5  文章 - 3  trackbacks - 0
<2006年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(3)

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

load进一个图片,如果对它进行放大缩小呢? 查找了很多地方的资料,找到以下的方法可以解决放大缩小图片问题: public static ImageIcon imageIconZoom(ImageIcon orgImageIcon, int newWidth, int newHeight) { BufferedImage tag = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); tag.getGraphics().drawImage(orgImageIcon.getImage(), 0, 0, newWidth, newHeight, null); return new ImageIcon(tag); } 如何对图片着色呢? static final float CRITICAL_BAND_MATRIX[][] = { { 1.0f, 0.0f, 0.0f , 0.0f}, { 0.0f, 0.0f, 0.0f , 0.0f}, { 0.0f, 0.0f, 0.0f,0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f } }; static final float MAJOR_BAND_MATRIX[][] = { { 1.0f, 0.0f, 0.0f , 0.0f}, { 0.0f, 0.5f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f , 0.0f}, { 1.0f, 0.5f, 0.0f, 0.0f } }; static final float MINOR_BAND_MATRIX[][] = { { 1.0f, 0.0f, 0.0f , 0.0f}, { 0.0f, 1.0f, 0.0f , 0.0f}, { 0.0f, 0.0f, 0.0f, 0.0f } , { 1.0f, 1.0f, 0.0f, 0.0f }}; static final float WARNING_BAND_MATRIX[][] = { { 0.5f, 0.0f, 0.0f , 0.0f}, { 0.0f, 0.0f, 0.0f , 0.0f}, { 0.0f, 0.0f, 1.0f , 0.0f} , { 0.5f, 0.0f, 1.0f, 0.0f }}; static final float CLEAR_BAND_MATRIX[][] = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f, 0.0f } }; static final float UNKNOWN_BAND_MATRIX[][] = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f , 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f } , { 0.0f, 0.0f, 1.0f, 0.0f }}; public static ImageIcon ColorImage(ImageIcon orgImage, int alarmStatus ){ float[][] targetMatrix ; switch(alarmStatus){ case CommonConstants.ALARM_UNKNOWN: targetMatrix = UNKNOWN_BAND_MATRIX; break; case CommonConstants.ALARM_CLEAR: targetMatrix = CLEAR_BAND_MATRIX; break; case CommonConstants.ALARM_MINOR: targetMatrix = MINOR_BAND_MATRIX; break; case CommonConstants.ALARM_MAJOR: targetMatrix = MAJOR_BAND_MATRIX; break; case CommonConstants.ALARM_CRITICAL: targetMatrix = CRITICAL_BAND_MATRIX; case CommonConstants.ALARM_WARNING: targetMatrix = WARNING_BAND_MATRIX; break; default: targetMatrix = UNKNOWN_BAND_MATRIX; } BufferedImage b1 ; BufferedImage biSrc = new BufferedImage(orgImage.getIconWidth(), orgImage.getIconHeight(), BufferedImage.TYPE_INT_ARGB); // biSrc.getGraphics().setColor(Color.white); // biSrc.getGraphics().fillRect(0, 0, orgImage.getIconWidth(), orgImage.getIconHeight()); biSrc.getGraphics().drawImage(orgImage.getImage(),0,0,null); BufferedImage biTar = new BufferedImage(orgImage.getIconWidth(), orgImage.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Raster srcRaster = biSrc.getRaster(); WritableRaster dstRaster = (WritableRaster) biTar.getRaster(); BandCombineOp bandCombineOp = new BandCombineOp(targetMatrix, null); bandCombineOp.filter(srcRaster, dstRaster); b1 = biTar; return new ImageIcon(b1); } 其中值得一说,却又说不清楚的地方是:BufferedImage.TYPE_INT_ARGB, 为什么要用TYPE_INT_ARGB,而不用TYPE_INT_RGB,之前我是用的TYPE_INT_RGB,而且matrix也是3*3的一个矩阵,后来发现,着色前,图片透明的地方,着色后,变成了黑色的了,于是猜想ARGB中的A应该是alphe的意思,就摸索构造了矩阵,并且着了实验,用是能用,不知道对不对啊。。。。
posted on 2006-12-29 16:38 托托姆 阅读(948) 评论(1)  编辑  收藏

FeedBack:
# re: java 中处理图片的操作(原创) 2006-12-29 17:01 BeanSoft
A 是透明的意思, 没错的.
参考偶的文章:http://www.blogjava.net/beansoft/ Java 中收取邮件并自动缩放图片的代码(原创)  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: