Good day,

I want to save a Model Image to a SQL Database, but the only way I can do this is to first call the Save method on the IPicture interface. This causes the image to be saved on the disk. From there I can use the image file to save it to the SQL Database. 

The only problem I have with this way is that it takes to long, I don't need it to be saved to the disk first.

Here is my code (Not Complete):

IPicture aModelPic = (IPicture) aModel.Graphic(false, false, mnLanguage);

//Save the Model Image to disk
aModelPic.Save(msPicsPath + "\\" + aModel.GUID() + ".png");

//Read the Model Image from disk to a ByteArrayInputStream 
File fModelImg = new File(msPicsPath + "\\" + aModel.GUID() + ".png");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedImage bufImg = ImageIO.read(fModelImg);
ImageIO.write(bufImg, "png", baos);
byte[] byteImage = baos.toByteArray();
ByteArrayInputStream inStream = new ByteArrayInputStream(byteImage);

//ready to write ByteArrayInputStream to SQL DB
PreparedStatement pstmt = mcxnDB.prepareStatement(msSql);

pstmt.setBinaryStream(1,inStream,inStream.available());
			
pstmt.executeUpdate();
pstmt.close();

What I need is a way to get either a InputStream or ImageInputStream directly from the IPicture interface to pass to ImageIO.read().

Is there a way to achieve this?

 or register to reply.

Notify Moderator