|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
需要对图片进行处理,使之能够适当的显示在画面中。找到一些资料后,处理也比较简朴代码: /* * AndyChen(andy.chen.sh@gmail.com) * **/ public static Icon getFixedBoundIcon(String filePath, int height, int width) throws Exception{ double Ratio=0.0; //缩放比例 File F = new File(filePath); if (!F.isFile()) throw new Exception(F+" is not image file error in getFixedBoundIcon!"); Icon ret = new ImageIcon(filePath); BufferedImage Bi = ImageIO.read(F); if ((Bi.getHeight()>height) || (Bi.getWidth()>width)){ if (Bi.getHeight()>Bi.getWidth()){ Ratio = (new Integer(height)).doubleValue() /Bi.getHeight(); } else { Ratio = (new Integer(width)).doubleValue()/Bi.getWidth(); } File ThF = new File(filePath+"_"+height +"_"+width); Image Itemp = Bi.getScaledInstance (width,height,Bi.SCALE_SMOOTH); AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null); Itemp = op.filter(Bi, null); try { ImageIO.write((BufferedImage)Itemp, "jpg", ThF); ret = new ImageIcon(ThF.getPath()); }catch (Exception ex) { } } return ret; } 返回类别: 教程 上一教程: hibernate in 查询 下一教程: Java开源工具系列(三)Struts 您可以阅读与"JAVA中图片文件的缩放"相关的教程: · 用JAVA将大图片文件转变出小的缩略图文件 · JAVA小程序源文件的组成 · JAVA中对文件的读写操作之比较 · java中找到资源文件的路径 · 上传图片的缩放处理 - 异常实用!(感谢loveyourvv兄弟) |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |