Mr. Boy
Mr. Boy

Reputation: 63748

MFC: Save from CImage to database as selected file-type

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?

Upvotes: 0

Views: 1097

Answers (1)

humbagumba
humbagumba

Reputation: 2074

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.

Upvotes: 3

Related Questions