1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
BOOL Images::_getthumb(INT index, IWICBitmapFrameDecode** image)
{
const INT thumbsize = 128;
IWICBitmapSource* datasource = NULL;
HRESULT hr = WICConvertBitmapSource(GUID_WICPixelFormat32bppBGR, (*image), &datasource);
BOOL ret = TRUE;
if (SUCCEEDED(hr))
{
UINT wid = _images[index]->Width;
UINT hgt = _images[index]->Height;
BYTE* data = new BYTE[wid * hgt * 4];
if (data)
{
hr = datasource->CopyPixels(0, wid * 4, wid * hgt * 4, data);
if (SUCCEEDED(hr))
{
if (_images[index]->Thumbnail)
{
DeleteObject(_images[index]->Thumbnail);
_images[index]->Thumbnail = NULL;
}
HDC screendc = GetDC(NULL);
HDC fulldc = CreateCompatibleDC(NULL); // for drawing from full-size bitmap
HDC thumbdc = CreateCompatibleDC(NULL); // for drawing to thumb-size bitmap
HBITMAP fullbitmap = CreateBitmap(wid, hgt, 1, 32, data);
_images[index]->Thumbnail = CreateCompatibleBitmap(screendc, thumbsize, thumbsize);
ReleaseDC(NULL, screendc);
DeleteObject(SelectObject(fulldc, fullbitmap));
DeleteObject(SelectObject(thumbdc, _images[index]->Thumbnail));
// get scale rect of full-size bitmap to fit in thumb bitmap
RECT scalerect = {0, 0, thumbsize, thumbsize};
// scale and copy from full bitmap to thumb bitmap
FillRect(thumbdc, &scalerect, (HBRUSH)GetStockObject(WHITE_BRUSH));
_getscalerect(index, &scalerect);
SetStretchBltMode(thumbdc, HALFTONE);
StretchBlt(thumbdc, scalerect.left, scalerect.top,
scalerect.right, scalerect.bottom, fulldc, 0, 0, wid, hgt, SRCCOPY);
DeleteObject(fullbitmap);
DeleteDC(fulldc);
DeleteDC(thumbdc);
}
else
ret = FALSE;
delete[] data;
data = NULL;
}
else
ret = FALSE;
datasource->Release();
datasource = NULL;
}
else
ret = FALSE;
return _images[index]->Thumbnail && ret? TRUE: FALSE;
}
|