what i am doing is a very simple image editing program and i have a problem with something. I saved the images in the database and converted it ImageIconso that it could go through the server sockets and such (serializable).
So, through VO, I get ImageIconin the GUI and convert it to BufferedImageso that I can edit it. But since I need to set the type of image, and there are many images with different types of images (at least it seems so), some photos turn into something that I did not want.
So basically I ask if there is another way to convert ImageIconto BufferedImage. Some ways to convert it without installing a single fixed image type. If not, I will have to give this part back.
The following is part of my code:
private class TableSelectEvent extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
int selectedRow = table.getSelectedRow();
loadedImageIcon = UserImageReceived.get(selectedRow).getImage();
originalImage = loadedImageIcon.getImage();
selectedImageName = UserImageReceived.get(selectedRow).getFileName();
if (originalImage != null) {
Image rbi = originalImage.getScaledInstance(lblSelectedImage.getWidth(), lblSelectedImage.getHeight(), Image.SCALE_SMOOTH);
lblSelectedImage.setIcon(new ImageIcon(rbi));
bimage = new BufferedImage(originalImage.getWidth(null), originalImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D bgr = bimage.createGraphics();
bgr.drawImage(originalImage, 0, 0, null);
bgr.dispose();
} else {
System.out.println("originalImage == null");
}
}
}
source
share