bool save_img(const CImage &image, vecByte &buf) {
IStream* stream = NULL;
HRESULT hr = CreateStreamOnHGlobal(0, TRUE, &stream);
if( !SUCCEEDED(hr) )
return false;
image.Save(stream, Gdiplus::ImageFormatBMP);
ULARGE_INTEGER liSize;
IStream_Size(stream, &liSize);
DWORD size_ = liSize.LowPart;
IStream_Reset(stream);
buf.resize(size_);
IStream_Read(stream, &buf[0], size_);
stream->Release();
return true;
}
bool load_img(const vecByte &buf, CImage &image) {
UINT len = buf.size();
HGLOBALhMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(hMem);
memcpy(pmem, &buf[0], len);
IStream*stream = NULL;
CreateStreamOnHGlobal(hMem, FALSE, &stream);
image.Load(stream);
stream->Release();
GlobalUnlock(hMem);
GlobalFree(hMem);
return true;
}