I have such problem: I have prepared in JAVA program that is supposed to save some data from picture and save them into txt file. Then the program is supposed to change into black all pixels of the picture in each 25th row and actualize the picture on the display (already with black lines). But something is wrong and I do not have any clue what - the whole picture is removed from diplay and nothing is displayed. Here is the code:
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt)
..........
BufferedImage out = new BufferedImage(in.getWidth(), in.getHeight(), in.getType());
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j=j+25) {
out.setRGB(i,j,0);
}
}
ImageIcon img = new ImageIcon(out);
imagePanel.removeAll();
imagePanel.setIcon(img);
} catch (IOException e) {
System.out.print("ERROR");
}
}
}
public static BufferedImage loadImage(File file) {
try {
BufferedImage out = ImageIO.read(file);
return out;
} catch (IOException e) {
return null;
}
}
I am using NetBeans and despite this everything works fine.
you create an empty image and you start drawing in each 25th line , in fact you should start with original image and start drawing in it.
// you create an empty image with same width and height of the original
//BufferedImage out = new BufferedImage(in.getWidth(), in.getHeight(), in.getType());
BufferedImage out = ImageIO.read(new File("path/to/Original/image"));
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j=j+25) {
out.setRGB(i,j,0);
}
}