I've been working on an update for file transfers and need some help:
How can resizing an image and get it's bytes be done properly? My workaround is saving to disk and then load again:
ResizeBitmap resize = { 0 };
if ((resize.hBmp = Bitmap_Load(ppszFiles[0])) == NULL)
return 0;
resize.size = sizeof(resize);
resize.fit = RESIZEBITMAP_KEEP_PROPORTIONS;
resize.max_height = resize.max_width = 100;
HBITMAP hbmpPreview = (HBITMAP)CallService(MS_IMG_RESIZE, (LPARAM)&resize, 0);
if (hbmpPreview == NULL)
return 0;
tstring abc = _T("WaImgTemp.jpg"); // temp image path
TCHAR tszTempFile[MAX_PATH];
_tcsncpy_s(tszTempFile, abc.c_str(), _TRUNCATE);
IMGSRVC_INFO saveInfo = { sizeof(saveInfo), 0 };
saveInfo.hbm = hbmpPreview;
saveInfo.tszName = tszTempFile;
saveInfo.dwMask = IMGI_HBITMAP;
saveInfo.fif = FIF_JPEG;
CallService(MS_IMG_SAVE, (WPARAM)&saveInfo, IMGL_TCHAR); // save image
HANDLE hFile = CreateFile(tszTempFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return NULL;
DWORD upperSize, lowerSize = GetFileSize(hFile, &upperSize);
std::vector<unsigned char> *result = new std::vector<unsigned char>(lowerSize);
ReadFile(hFile, (void*)result->data(), lowerSize, &upperSize, NULL);
CloseHandle(hFile);
fmsg->icondata = result;