Load a redrawn image into a JLabel and save it into a BufferedImage?
881879Dec 25 2011 — edited Dec 27 2011Hello, I'm doing a small application to rotate an image, it works, but I'd like to show it into a JLabel that I added, and also store the converted image into a BufferedImage to save it into a database, this is what I have so far:
public void getImage() {
try{
db_connection connect = new db_connection();
Connection conn = connect.getConnection();
Statement stmt = conn.createStatement();
sql = "SELECT image " +
"FROM image_upload " +
"WHERE image_id = 1";
rset = stmt.executeQuery(sql);
if(rset.next()){
img1 = rset.getBinaryStream(1);
buffImage = ImageIO.read(img1);
}
rset.close();
} catch(Exception e){
System.out.println(e);
}
}
public void paint(Graphics g){
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
ImageIcon imgIcon = new ImageIcon(buffImage);
AffineTransform tx = AffineTransform.getRotateInstance(rotacion, imgIcon.getIconWidth()/2, imgIcon.getIconHeight()/2);
g2.drawImage(imgIcon.getImage(), tx, this);
jLabel1.setIcon(imgIcon);
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
setRotacion(getRotacion() + 1.5707963249999999);
repaint();
}
I get the image from a db, then using the paint() method I rotate the image, it works, but the new image is outside of the JLabel and I don't know how to assign the new one into the JLabel (like overwritting the original) and also how to store the new image into a BufferedImage to upload it into the database converted, thanks in advanced, any help would be appreciated, thanks!!
Edited by: saman0suke on 25-dic-2011 14:07
Edited by: saman0suke on 25-dic-2011 15:08