tags:

views:

150

answers:

1

I am extracting images from a MySQL database using the MySQL++ API. I get the images as mysqlpp::sql_mediumblob which is representation of string. Now I want to rotate some pictures using GDI+, but I am not sure how to use this constructor:

Image::Image(IStream*,BOOL) - Creates an Image object based on a stream.

with the image that is kept in the blob. Thanks in advance.

+1  A: 

As noted here: http://msdn.microsoft.com/en-us/library/aa378980(VS.85).aspx

HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE,iSize);
if (!hMem)
    AfxThrowMemoryException();
LPVOID pImage = ::GlobalLock(hMem);
... // Fill memory pointed by pImage, reading it from MySQL
::GlobalUnlock(hMem);

// Convert internal data if there is any
CComPtr<IStream> spStream;
HRESULT hr = ::CreateStreamOnHGlobal(hMem,FALSE,&spStream);

Then pass spStream to the Gdiplus::Image constructor.

Ivan Krechetov
Can the Win32 API get any uglier?
Judge Maygarden
Yep. I'm sure they have some good reasons... Well, they'd better do!
Ivan Krechetov