So I have been trying to create a stretched bitmap from a bitmap that I receive via a function call and stretch it so a user defined size.
Here is my code that isn't working
// I know my bitmap even stretched is not over 64k
// For this please assume that bih and bmiHeader are valid if you find no problem with this code I can give you that information, 'thank you'.
// pSubBuffer - Buffer of bitmap
// bih is Bitmap info head for pSubBuffer
// bmiHeader is requested new info for new bitmap
BYTE* CreateStretchedBitmap(BYTE*pSubBuffer, BITMAPINFOHEADER bih, BITMAPINFOHEADER bmiHeader)
{
SetStretchBltMode(hdcDst,HALFTONE);
result = StretchBlt(hdcDst, 0,0, bmiHeader.biWidth, bmiHeader.biHeight, hdcSrc,0, 0, nWidth, nHeight, SRCCOPY);
// result is 1 here
HANDLE hDIB = GlobalAlloc(GHND, bmiHeader.biSizeImage);
char *lpbitmap = (char *)GlobalLock(hDIB);
result = GetDIBits(hdcDst, hbmNew, 0, bmiHeader.biHeight, lpbitmap, (BITMAPINFO*)&bmiHeader, DIB_RGB_COLORS);
// result returns 0 here and there is no error from GetLastError()
Re: Taking a bitmap and stretching it to a new bitmap
Please use code tags.
Well it works for me ( I get a good value for "result" after calling GetDIBits ) after fixing the undefined nWidth, nHeight. I get a monochrome bitmap though. You need to pass a real DC to your CreateDIBitmap function otherwise your newly created memory DCs only have a monochrome bitmap. Try using the desktop DC instead:
Code:
//Add this line:
HDC hdcDesktop = GetDC(NULL);
HDC hdcSrc = CreateCompatibleDC(NULL);
HDC hdcDst = CreateCompatibleDC(NULL);
HBITMAP hBit, hbmOld, hbmOld2, hbmNew;
hBit = CreateDIBitmap(hdcDesktop, &bih, CBM_INIT, (void*)pSubBuffer, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
hbmNew = CreateDIBitmap(hdcDesktop, &bmiHeader, 0, NULL, NULL, DIB_RGB_COLORS);
//the rest is the same except I changed to get it to compile:
result = StretchBlt(hdcDst, 0,0, bmiHeader.biWidth, bmiHeader.biHeight, hdcSrc,0, 0, bih.biWidth, bih.biHeight, SRCCOPY);
Re: Taking a bitmap and stretching it to a new bitmap
I tried using your code and it doesn't seem to work in my particular case. The bibitCount is not always 32 since it will depend on the device. The Original BITMAPINFOHEADER comes from a VIDEOINFOHEADER which in turn is from an AM_MEDIA_TYPE. Here is the bih
Bookmarks