I have stored some images in database, while retrieving them i want to resize it to 177×122. How can i do that in JAVA?
Here is some code that i have used to retrieve image from database, what changes need to be done to get a image of 177×122.
PreparedStatement pstm1 = con.prepareStatement("select * from image");
ResultSet rs1 = pstm1.executeQuery();
while(rs1.next()) {
InputStream fis1;
FileOutputStream fos;
String image_id;
try {
fis1 = rs1.getBinaryStream("image");
image_id=rs1.getString("image_id");
fos = new FileOutputStream(new File("images" + (image_id) + ".jpg"));
int c;
while ((c = fis1.read()) != -1) {
fos.write(c);
}
fis1.close();
fos.close();
JOptionPane.showMessageDialog(null, "Image Successfully Retrieved");
} catch (Exception ex) {
System.out.println(ex);
}
}
You can use the AWT provided BufferedImage and Graphics2D classes to resize your images. Source