what I'm making is very simple image editing program and I have a problem with something. I saved the images in DB and converted it as a ImageIcon so that it can go through server sockets and such (serializable).
So through the VO I get the ImageIcon to GUI and convert it to BufferedImage so that I can edit that. But since I have to set the image type and there are a lot of pictures with different image types (at least it seems so), some pictures turn into something I didn't want them to be.
So, basically I'm asking if there's is another way to convert ImageIcon to BufferedImage. Some ways to convert it without setting the one single, fixed image type. If there is none I'll have to give that part up.
Below is some 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);
// this, BufferedImage.TYPE_INT_ARGB part is the problem I'm having!
Graphics2D bgr = bimage.createGraphics();
bgr.drawImage(originalImage, 0, 0, null);
bgr.dispose();
} else {
System.out.println("originalImage == null");
}
}
}