首页 > 其他 > 详细

图片压缩处理方法

时间:2016-01-21 18:24:40      阅读:151      评论:0      收藏:0      [点我收藏+]
	 
public String delPicture(String filePath,int outputWidth,int outputHeight,String outputPath) { //参数分别代表的意思:源文件,输出高度,输出宽度,输出文件路径 try { //获得源文件 file = new File(filePath); if (!file.exists()) { return ""; } Image img = ImageIO.read(file); // 判断图片格式是否正确 if (img.getWidth(null) == -1) { //System.out.println("无法读取" + "<BR>"); return "no"; } else { int newWidth; int newHeight; newWidth = outputWidth; // 输出的图片宽度 newHeight = outputHeight; // 输出的图片高度 BufferedImage tag = new BufferedImage((int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB); /* * Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的 * 优先级比速度高 生成的图片质量比较好 但速度慢 */ tag.getGraphics().drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); FileOutputStream out = new FileOutputStream(outputPath); // JPEGImageEncoder可适用于其他图片类型的转换 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } catch (IOException ex) { ex.printStackTrace(); } return "ok"; }

  

图片压缩处理方法

原文:http://www.cnblogs.com/driftking/p/5148544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!