BufferedImage image = Images.read(tf.getFile());
JDK1.8,tomcat8
这样写更好一些
UserProfile profile = get();
try (InputStream ins = tf.getInputStream()) {
BufferedImage image = Images.read(ins);
image = Images.zoomScale(image, 128, 128, Color.WHITE);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Images.writeJpeg(image, out, 0.8f);
profile.setAvatar(out.toByteArray());
dao.update(profile, "^avatar$");
} catch(DaoException e) {
log.info("System Error", e);
msg = "系统错误";
} catch (Throwable e) {
msg = "图片格式错误";
}
@wendal 谢谢兽总。。刚刚我也发现getFile过时了,不知道怎么获取file对象。。受教了