我正在尝试编写一些简单的代码来调整图像大小,我收到了JVM崩溃。据我所知,我正在使用API。这是代码:
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
public class Resizer {
public static void main(String[] args) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("C:\\Users\\Owner\\Desktop\\export\\10.jpg"));
} catch (IOException e) {
System.out.println(e);
return;
}
RescaleOp ro = new RescaleOp(1.25f, 0.0f, null);
BufferedImage output = ro.filter(img, null); //JVM CRASHES ON THIS LINE
// Also crashes if I use these lines instead:
//BufferedImage output = ro.createCompatibleDestImage(img, img.getColorModel());
//ro.filter(img, output);
try {
ImageIO.write(output, "png", new File("C:\\Users\\Owner\\Desktop\\export\\10.output.png"));
} catch (IOException ioe) {
System.out.println(ioe);
return;
}
}
}
我收到了这个错误:
# # An unexpected error has been detected by Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d524c5d, pid=13076, tid=11172 # # Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode windows-x86) # Problematic frame: # C [mlib_image.dll+0x54c5d] # # An error report file with more information is saved as: # C:\Users\Owner\Documents\src\Java\ImageSizer\hs_err_pid13076.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. #
答案 0 :(得分:3)
这很可能是JVM中的一个错误,因为通常只有本机代码才能使JVM崩溃,并且它看起来不像您正在使用任何第三方内容。你并不是唯一遇到这个问题的人。请参阅this message及其回复。特别参见this message,可以帮助您在没有此JVM崩溃的情况下执行您要执行的操作。
这是一个已知问题。有关详细信息,请参阅Sun Bug ID 4886506。 Sun错误报告包含可能对您有所帮助的解决方法。看起来这个bug在JDK 7中得到了修复。