Friday, 25 March 2016

java - Display BufferedImage in JPanel

I get an Image as a Blob from a database and want to draw it into a JPanel. If i run the following code nothing is drawn but there isn't an error. Can anyone tell me what's wrong? I Never worked with images in java...



Blob image = rs.getBlob("com_img");
Graphics2D g2;
BufferedImage img;

try {
img = ImageIO.read(image.getBinaryStream());
g2 = (Graphics2D)ImageIO.read(image.getBinaryStream()).getGraphics();
g2.drawImage(img,0,0, panel);
panel.paint(g2);


} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();

}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...