这是我的代码:
for (int i = 0 ;i < starting.Element_N ;i++) {
String name = starting.AllImages[i];
File[] files = new File("element/" + name + "/").listFiles();
for (File file : files) {
if (file.isFile() == true) {
try {
BufferedImage four2 = ImageIO.read(new File("element/" + name + "/" + file.getName()));
int w = (int)Double.parseDouble(NewImagesSize.getText());
int h = 100;//(int)((double)four.getHeight()/((double)four.getWidth()/(double)w));
BufferedImage image_copy = four2;
four2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image_copy.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(image_copy, 0, 0, w, h, null);
g2.dispose();
File ouptut = new File(file.getName().substring(0,3));
ImageIO.write(four2, "jpg", ouptut);
}
catch (IOException e) {}
}
}
}
这些错误显示编译器(netbeans 8):
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at AA.ResizeImage.jButton1ActionPerformed(ResizeImage.java:132)
at AA.ResizeImage.access$000(ResizeImage.java:24)
at AA.ResizeImage$1.actionPerformed(ResizeImage.java:64)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
...
我想调整java中某个文件夹中的所有图像的大小。 如果有这个程序的来源,就把它。 非常感谢。