NutzCN Logo
问答 上传头像的tf.getFile(),不可用
发布于 2968天前 作者 dahaoqiu 1747 次浏览 复制 上一个帖子 下一个帖子
标签:

BufferedImage image = Images.read(tf.getFile()); QQ图片20160304170728_png

JDK1.8,tomcat8

3 回复

这个不是不可以,是方法标注了过去,只是不建议使用

这样写更好一些

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对象。。受教了

添加回复
请先登陆
回到顶部