//上传图片
@At("/uploadimg")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class,args = { "/uploadTemp", "8192", "UTF-8", "1000" })
public NutMap upload(
@Param("image_file") TempFile tf,
HttpServletRequest req,
ServletContext context) throws SQLException, IOException {
NutMap m=new NutMap();
String md5;
String prefix;
long nowtime=System.currentTimeMillis();
@SuppressWarnings("deprecation")
InputStream fis = tf.getInputStream();
File f = tf.getFile(); // 这个是保存的临时文件
FieldMeta meta = tf.getMeta();
prefix = getprefix(f);
Iterator readers = ImageIO.getImageReadersByFormatName("jpg");
ImageReader reader=(ImageReader)readers.next();
ImageInputStream iis = ImageIO.createImageInputStream(fis);
reader.setInput(iis, true);
ImageReadParam param=reader.getDefaultReadParam();
Rectangle rect= new Rectangle(0, 0, 10, 10);
param.setSourceRegion(rect);
BufferedImage bi=reader.read(0, param);
ImageIO.write(bi, "jpg", new File("E:\\upload\\jxweike\\" +nowtime+"."+ prefix));
报错了 在倒数第二行,生成图片的时候报错了 Not a jpeg file
正如 群里大佬所说,上传的图片是jpg 后缀 但不是jpeg 格式的, 对于这种情况 代码改如何改进,求大佬指点 !我是要实现剪切头像的功能的!