想对jpeg格式图像进行压缩(不是缩略图),压缩后还是jpeg格式,在java中如何实现 告诉我具体用到哪些类中的哪些方法也行。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try { // 压缩前的JPEG文件 File srcFile = new File("c:\\src.jpg"); // 压缩前后的JPEG文件 File dstFile = new File("c:\\dst.jpg"); // 压缩百分比 float quality = 0.75f; BufferedImage srcImage = ImageIO.read(srcFile); Iterator it = ImageIO.getImageWritersBySuffix("jpg"); if (it.hasNext()) { FileImageOutputStream fileImageOutputStream = new FileImageOutputStream(dstFile); ImageWriter iw = (ImageWriter) it.next(); ImageWriteParam iwp = iw.getDefaultWriteParam(); iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); iwp.setCompressionQuality(quality); iw.setOutput(fileImageOutputStream); iw.write(null, new IIOImage(srcImage, null, null), iwp); iw.dispose(); fileImageOutputStream.flush(); fileImageOutputStream.close(); } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } jpeg已经是压缩过的图片了,基本上不能再压缩太多了 一道java题目不懂什么意思,请教一下 又是对象流,对象中有对象属性,我如何序列化保存它 关于JGraph里设置工具提示问题 java双线程的理解 在不同的包里, 但属于继承关系的2个类能访问protected修饰的变量吗 可以列举一些,基于接口的,可插拨的系统源码框架吗? resin集群支持多少台机器? 又一个swing的问题,快来救我啊!!! 高手来帮我启动cloudview~~~(人工呼吸) package的问题:能否这样 commons.net.ftp.FTPClient为什么不能取出linux服务上的ftp文件列表? 郁闷啊~输入全班成绩,算出平均成绩、最高分、最低分等
// 压缩前的JPEG文件
File srcFile = new File("c:\\src.jpg");
// 压缩前后的JPEG文件
File dstFile = new File("c:\\dst.jpg");
// 压缩百分比
float quality = 0.75f;
BufferedImage srcImage = ImageIO.read(srcFile);
Iterator it = ImageIO.getImageWritersBySuffix("jpg");
if (it.hasNext()) {
FileImageOutputStream fileImageOutputStream = new FileImageOutputStream(dstFile);
ImageWriter iw = (ImageWriter) it.next();
ImageWriteParam iwp = iw.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(quality);
iw.setOutput(fileImageOutputStream);
iw.write(null, new IIOImage(srcImage, null, null), iwp);
iw.dispose();
fileImageOutputStream.flush();
fileImageOutputStream.close();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}