I'm trying to convert a image file (a png, but could be anything) that I just extracted into memory from a compressed file to a ID2D1Bitmap to draw using Direct 2D. I tried to look for some documentation, but I can only find methods that receive "const char* path" or ask me width and height of my image, that I can't know before-hand. Searching on google for it got me nowhere.
The file is raw in memory, and I would like to avoid to extract images to the hdd into a temporary file just to read their data from there.
Any ideas?
if you have the HBITMAP handle, you can do this:
::GetObject(hBmp, sizeof(BITMAP), &bmpSizeInfo);
fill a BITMAPINFO like this:
memset(&bmpData, 0, sizeof(BITMAPINFO)); bmpData.bmiHeader.biSize = sizeof(bmpData.bmiHeader); bmpData.bmiHeader.biHeight = -bmpSizeInfo.bmHeight; bmpData.bmiHeader.biWidth = bmpSizeInfo.bmWidth; bmpData.bmiHeader.biPlanes = bmpSizeInfo.bmPlanes; bmpData.bmiHeader.biBitCount = bmpSizeInfo.bmBitsPixel;
create enough heap memory to hold the data for your bitmap:
pBuff = new char[bmpSizeInfo.bmWidth * bmpSizeInfo.bmHeight * 4];
Get the bitmap data like this:
::GetDIBits(hDc, hBmp, 0, bmpSizeInfo.bmHeight, (void*)pBuff, &bmpData, DIB_RGB_COLORS);
Create a
D2D1_BITMAP_PROPERTIES
and fill it like this:bmpPorp.dpiX = 0.0f; bmpPorp.dpiY = 0.0f; bmpPorp.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; bmpPorp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
Using your render target turn the data into ID2D1Bitmap
pRT->CreateBitmap(bmpSize, pBuff, 4 * bmpSizeInfo.bmWidth, bmpPorp, &pBmpFromH);
Hope this can help.
Sam