>Now you've got int's, not bytes. I assume that's what you want.
>>Now you've got int's, not bytes. I assume that's what you want.
>
[quoted text clipped - 4 lines]
>but it didn't work.
>The final array of bytes is not an image, unfortunately.
Hi,
I have exactely the same problem. I've found a workaround, I use a
file as an intermediate stage, it works fine but it is a heresy in
efficiency terms.
Cyril Mrazek
Connection con;
BufferedImage bimg;
//... get con
//... get bimg
File fiDummy = new File("dummy.jpg");
FileImageOutputStream fios = new FileImageOutputStream(fiDummy);
ImageWriter iw = ImageIO.getImageWriterBySuffix("jpg");
iw.setOutput(fios);
iw.write(bimg);
fios.close();
// the column "image" int the table "album" is a Blob
PreparedStatement pstm = con.prepareStatement("UPDATE album SET
image=? WHERE name=?");
FileInputStream fis = new FileInputStream(fiDummy);
pstm.setBinaryStream(1, fis, (int) fiDummy.length());
pstm.setString(2, _name);
pstm.executeUpdate();
fis.close();
rs.close();
Cyril Mrazek - 19 Feb 2004 09:02 GMT
without the rs, sorry, I copied one line too much.
CM
Connection con;
BufferedImage bimg;
//... get con
//... get bimg
File fiDummy = new File("dummy.jpg");
FileImageOutputStream fios = new FileImageOutputStream(fiDummy);
ImageWriter iw = ImageIO.getImageWriterBySuffix("jpg");
iw.setOutput(fios);
iw.write(bimg);
fios.close();
// the column "image" int the table "album" is a Blob
PreparedStatement pstm = con.prepareStatement("UPDATE album SET
image=? WHERE name=?");
FileInputStream fis = new FileInputStream(fiDummy);
pstm.setBinaryStream(1, fis, (int) fiDummy.length());
pstm.setString(2, _name);
pstm.executeUpdate();
fis.close();
Bilbo Baggins - 19 Feb 2004 12:13 GMT
>Hi,
>I have exactely the same problem. I've found a workaround, I use a
>file as an intermediate stage, it works fine but it is a heresy in
>efficiency terms.
I solved the problem:
// iconData is the original array of bytes
ImageIcon imageIcon = new ImageIcon(iconData);
Image img = imageIcon.getImage();
Image imageResize = img.getScaledInstance(100, 100, 0);
ImageIcon imageIconResize = new ImageIcon (imageResize);
int resizeWidth = imageIconResize.getIconWidth();
int resizeHeight = imageIconResize.getIconHeight();
Panel p = new Panel();
BufferedImage bi = new BufferedImage(resizeWidth, resizeHeight,
BufferedImage.TYPE_INT_RGB);
Graphics2D big = bi.createGraphics();
big.drawImage(imageResize, 0, 0, p);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
encoder.encode(bi);
byte[] byteArray = os.toByteArray();
Cyril Mrazek - 19 Feb 2004 12:42 GMT
Great! Next step is to make it generic for all supported graphics
types.
CM
>I solved the problem:
>
[quoted text clipped - 21 lines]
>encoder.encode(bi);
>byte[] byteArray = os.toByteArray();
Bilbo Baggins - 19 Feb 2004 12:47 GMT
>Great! Next step is to make it generic for all supported graphics
>types.
For BMP images take a look at:
http://sourceforge.net/projects/javaexplorer/
Renato Gondim - 25 Mar 2005 11:43 GMT
It's not working, just saves a black window in the database.
What's wrong?