主要是从手机端传图片到服务器,服务器会对图片进行一下压缩,
但是现在一直没有好的压缩方法,现在用的压缩方法,
总是有一定的概率出现图片是全白的情况,而且概率还不低,有2%~5%左右。
各位有什么好的压缩图片的方法吗?
或者说针对图片全白的情况有什么建议,
手机端上传图片到服务器有什么好的办法吗?
但是现在一直没有好的压缩方法,现在用的压缩方法,
总是有一定的概率出现图片是全白的情况,而且概率还不低,有2%~5%左右。
各位有什么好的压缩图片的方法吗?
或者说针对图片全白的情况有什么建议,
手机端上传图片到服务器有什么好的办法吗?
解决方案 »
- Myeclipse 导入项目
- 怎么在服务器上运行一段驻留程序?
- 在JSP网页编程中遇到了以下问题,求解决
- 求:javascript,怎么让图片做为提交按钮啊?
- package的问题
- struts的幼稚问题
- 关于JavaBean在JSP页面调用的问题(初学)
- 有没有jsp和servlet这两个能配合使用吗?有没有例子?
- servlet与resin的配置问题
- cas 客户端登录成功不跳转到客户端页面 而是跳转到一个页面导航 可以选择进入到任何一个客户端
- 请教:java用openoffice将doc,ppt等文档转换为pdf文件,再将pdf文件转成swf文件,最后用flexplayer播放
- JAVA Servlet 无组件实现HTTP上传文件时DataInputStream.read方法发出超时异常
~~~~~~~~~~~~~~~~~~~~
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.Color;
import java.io.*;
import java.util.*;
...
private String generateThumbnail(String fileNameRaw, String fileExt, int thumbWidth, int thumbHeight) {
String ret = null;
try {
// Calculate thumbnail rate.
File fileRaw = new File(fileNameRaw);
BufferedImage rawImage = ImageIO.read(fileRaw);
double rawWidth = rawImage.getWidth();
double rawHeight = rawImage.getHeight();
double rateWidth = thumbWidth / rawWidth;
double rateHeight = thumbHeight / rawHeight;
double rate = Math.min(rateWidth, rateHeight);
rate = (Math.rint((rate * 100) + 0.5)) / 100;
// Generate thumbnail image, using ext jpg.
BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_USHORT_565_RGB);
Graphics2D thumbGraph = thumbImage.createGraphics();
thumbGraph.setBackground(Color.WHITE);
thumbGraph.clearRect(0, 0, thumbWidth, thumbHeight);
AffineTransform trans = new AffineTransform();
trans.scale(rate, rate);
AffineTransformOp transOP = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
thumbGraph.drawImage(rawImage, transOP, (int) (thumbWidth - (rawWidth * rate)) / 2, (int) (thumbHeight - (rawHeight * rate)) / 2);
String fileNameThumb = fileNameRaw + fileExt;
File fileThumb = new File(fileNameThumb);
if (fileThumb.exists()) {
fileThumb.delete();
}
fileThumb.createNewFile();
ImageIO.write(thumbImage, "jpg", fileThumb);
ret = fileNameThumb;
} catch (Exception e) {
}
return ret;
}
http://blog.csdn.net/yjflinchong/article/details/7579077刚发布的