views:

14

answers:

1

We have a requirement that a user can load any standard image into a dialog, the image is displayed, and the image saved as a specific format (JPG) in a database. It seems CImage is the class to be using since it can load and save BMP/GIF/JPG/PNG. But is there an easy way to save the JPG as a BLOB in the database without calling CImage::Save and then loading the file to memory - we don't want to save the file even temporarily.

Any ideas?

+2  A: 

CImage::Save has two overloads. You could use

HRESULT Save(
   IStream* pStream,
   REFGUID guidFileType
) const throw();

to save the image to an IStream. You could write your own simple IStream implementation or could try to use the CreateStreamOnHGlobal function, which creates an IStream object on an HGLOBAL.

humbagumba