【发布时间】:2013-04-04 18:02:36
【问题描述】:
当我像这样简单地从另一个创建新图像时:
public static void scaleByTwoRight(String src, String dest)
throws IOException {
BufferedImage bsrc = ImageIO.read(new File(src));
int width = bsrc.getWidth()/2;
int height = bsrc.getHeight();
BufferedImage bdest = bsrc.getSubimage(width, 0, width, height);
ImageIO.write(bdest,"PNG",new File(dest));
}
源文件 (src) = C:...\Manga\Shonan Juna_ Gumi Tome 11\Shonan Junaï Gumi Tome 11 - 091B.png 目标文件 (dest) = C:...\Manga\Shonan Junaï Gumi Tome 11 - 091B_A.png
生成文件示例:https://docs.google.com/file/d/0B1vKCZzB5hxqYzNsUWF5RHA2Wm8/edit?usp=sharing
问题:新图像具有 mimetype: application 而不是 mimetype: image
我是如何得出这个结论的:我正在使用一个函数来测试文件是否为图像:
public static boolean isImage(String src)
throws IOException {
File f = new File(src);
String mimetype= new MimetypesFileTypeMap().getContentType(f);
String type = mimetype.split("/")[0];
if(type.equals("image")){
return true;
}else{
System.out.println("mimetype: "+type);
return false;
}
}
如果 Mime 类型不正确,影响不大,但我更喜欢让它正常工作..
感谢您的帮助!
注意: 我在 Windows 7 / 32b 下运行 JVM 1.7 / Eclipse Helios
【问题讨论】:
-
String destdest的值是多少?请以SSCCE 的形式回答。 -
Function : scaleByTwoRight(String src, String dest) 源文件 (src) = C:\...\Manga\Shonan Juna_ Gumi Tome 11\Shonan Junaï Gumi Tome 11 - 091B.png 目标文件(dest) = C:\...\Manga\Shonan Junaï Gumi Tome 11 - 091B_A.png
-
请查找运行 scaleByTwoRight 函数后创建的目标(图像)示例:docs.google.com/file/d/0B1vKCZzB5hxqYzNsUWF5RHA2Wm8/…
-
1) 不要将代码放在 cmets 或链接中,直接将它们添加为 edit to the question 2) 为了尽快获得更好的帮助,请发布 SSCCE。
标签: java image file-io mime-types