ImageIO读jpg的时分出现javax.imageio.IIOException: Unsupported Image Type

小白-记事本 2013-12-27 10:08:38
走到这步报错“ImageIO读jpg的时分出现javax.imageio.IIOException: Unsupported Image Type

BufferedImage src = javax.imageio.ImageIO.read(imgfile); // 构造Image对象
是什么情况,下面是具体代码。跪求大神


public FileInfo[] addPhotoFile(String[] names, String mkDirectory,
Long sbmh, Long sysyear) {
String message = "";
mkDirectory = mkDirectory.toUpperCase();
FileInfo[] FileInBean = new FileInfo[names.length];
List<SystemParameter> list = commonService.getSysByCodeclass("SYS_"
+ mkDirectory + "_FILEUPLODFORMAT", null, sysyear);
ArrayList<String> arr = new ArrayList<String>();
this.setIsok(true);

for (int i = 0; i < names.length; i++) {
String filename = get(names[i] + "FileName"); // 文件名称
String filetype = get(names[i] + "ContentType"); // 文件格式
File[] fil = (File[]) ActionContext.getContext().getParameters()
.get(names[i]); // 文件
this.setFile(fil);
if (fil != null && fil.length > 0) {
if (!(filename == null || "".equals(filename))) {
if (isFomartTrue(list, filetype)) {
Date dat = new Date();
Random random = new Random(99);
int k = random.nextInt(100);
String wjName = sbmh + "" + dat.getSeconds() + "" + k;
try {
String file_Path = this.getUploadDirectory()
+ "/"
+ mkDirectory
+ "/"
+ wjName
+ filename.substring(filename.indexOf("."),
filename.length());
FileUtils.copyFile(file[0], new File(file_Path));
javax.imageio.ImageIO.setUseCache(false);

File imgfile = new File(file_Path); // 读入文件


BufferedImage src = javax.imageio.ImageIO
.read(imgfile); // 构造Image对象
int width = src.getWidth(null); // 得到源图宽
int height = src.getHeight(null); // 得到源图长
int imgwidth = 150;
int imgheight = 200;
if (width > imgwidth) {
this.setMessage(message
+ "图片宽度超过限制,请上传宽度小于150px的照片,当前照片宽度为:"
+ width + "px!");
this.setIsok(false);
File f = new File(file_Path);
f.delete();
break;
}
if (height > imgheight) {
this.setMessage(message
+ "图片高度超过限制,请上传高度小于200px的照片,当前照片高度为:"
+ height + "px!");
this.setIsok(false);
File f = new File(file_Path);
f.delete();
break;

}
if (file[0].length() > 102400) {
this.setMessage(message
+ "对不起,上传照片大小不能超过100KB!");
this.setIsok(false);
File f = new File(file_Path);
f.delete();
break;
}
arr.add(file_Path);
FileInBean[i] = new FileInfo();
FileInBean[i].setFilename(filename);
FileInBean[i].setFileformat(filetype);
FileInBean[i].setFilepath(file_Path);
FileInBean[i].setFiletitle(filename.substring(0,
filename.indexOf(".")));
file[0].delete();
} catch (Exception e) {
e.printStackTrace();
System.out.println("文件上传异常" + e.getMessage());
this.setMessage(message + "第 " + (i + 1)
+ " 个文件上传失败!");
this.setIsok(false);
break;
}
} else {
this.setMessage(message + "第 " + (i + 1)
+ " 个文件上传失败,文件格式不正确");
this.setIsok(false);
break;
}
} else {
this.setMessage(message + "第 " + (i + 1)
+ " 个文件上传失败,该文件不存在 ");
this.setIsok(false);
break;
}
} else {
this.setMessage(message + "第 " + (i + 1) + " 个文件上传失败,该文件不存在 ");
this.setIsok(false);
break;
}
}
if (!this.getIsok()) {
for (String Fil : arr) {
File f = new File(Fil);
f.delete();
}
}

return FileInBean;
}
...全文
3028 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
P过的图片保存为jpg格式时,默认的模式是CMYK模式(注意,这是给印刷机用的)。在图像-->模式中改为RGB模式才是显示器用的
  • 打赏
  • 举报
回复
不支持这种类型。你的图片后缀是jpg但是内容可能不是。Java只支持一些基本类型的图片,当然包括jpg。其他类型直接找包。
tony4geek 2014-05-30
  • 打赏
  • 举报
回复
Unsupported Image Type
洋洋宣宣 2014-05-30
  • 打赏
  • 举报
回复
解决了么?这个问题很神奇啊。。
小白-记事本 2013-12-27
  • 打赏
  • 举报
回复
怎么解决呢。。。
tony4geek 2013-12-27
  • 打赏
  • 举报
回复
应该是图片格式错误了。

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧