MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » javax.imageio.IIOException: Unsupported Image Ty

javax.imageio.IIOException: Unsupported Image Type,该如何处理(2)

www.MyException.Cn  网友分享于:2013-12-27  浏览:1314次

// 则将下面的if else语句注释即可
/*if (sx > sy) {
sx = sy;
targetW = (int) (sx * source.getWidth());
} else {
sy = sx;
targetH = (int) (sy * source.getHeight());
}*/
if (type == BufferedImage.TYPE_CUSTOM) { // handmade
ColorModel cm = source.getColorModel();
WritableRaster raster = cm.createCompatibleWritableRaster(targetW,
targetH);
boolean alphaPremultiplied = cm.isAlphaPremultiplied();
target = new BufferedImage(cm, raster, alphaPremultiplied, null);
} else
target = new BufferedImage(targetW, targetH, type);
Graphics2D g = target.createGraphics();
// smoother than exlax:
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy));
g.dispose();
return target;
}

public static void saveImageAsJpg(String fromFileStr, String saveToFileStr,
int width, int hight) throws Exception {
BufferedImage srcImage;
// String ex =
// fromFileStr.substring(fromFileStr.indexOf("."),fromFileStr.length());
System.out.println("源图片地址:"+fromFileStr);
System.out.println("小图片地址:"+saveToFileStr);
String imgType = "JPEG";
if (fromFileStr.toLowerCase().endsWith(".png")) {
imgType = "PNG";
}
// System.out.println(ex);
File saveFile = new File(saveToFileStr);
File fromFile = new File(fromFileStr);
srcImage = ImageIO.read(fromFile);
if (width > 0 || hight > 0) {
srcImage = resize(srcImage, width, hight);
}
ImageIO.write(srcImage, imgType, saveFile);

}
}

------解决方案--------------------
图片格式不对吧
是cmyk模式的图片吗
------解决方案--------------------
能正常切图的和不能的一点儿区别都没有吗?

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有