MCPcopy Create free account
hub / github.com/LegacyUpdate/LegacyUpdate / GetHBitmapForWICBitmap

Function GetHBitmapForWICBitmap

shared/LoadImage.c:108–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108static HBITMAP GetHBitmapForWICBitmap(IWICBitmapSource *bitmap) {
109 HBITMAP hBitmap = NULL;
110 UINT width = 0, height = 0;
111 if (!SUCCEEDED(IWICBitmapSource_GetSize(bitmap, &width, &height)) || width == 0 || height == 0) {
112 return NULL;
113 }
114
115 BITMAPINFO bminfo = {0};
116 ZeroMemory(&bminfo, sizeof(bminfo));
117 bminfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
118 bminfo.bmiHeader.biWidth = width;
119 bminfo.bmiHeader.biHeight = -(LONG)height;
120 bminfo.bmiHeader.biPlanes = 1;
121 bminfo.bmiHeader.biBitCount = 32;
122 bminfo.bmiHeader.biCompression = BI_RGB;
123
124 void *imageBits = NULL;
125 HDC screenDC = GetDC(NULL);
126 hBitmap = CreateDIBSection(screenDC, &bminfo, DIB_RGB_COLORS, &imageBits, NULL, 0);
127 ReleaseDC(NULL, screenDC);
128 if (!hBitmap) {
129 return NULL;
130 }
131
132 UINT stride = width * 4;
133 UINT imageSize = stride * height;
134 if (!SUCCEEDED(IWICBitmapSource_CopyPixels(bitmap, NULL, stride, imageSize, (BYTE*)imageBits))) {
135 DeleteObject(hBitmap);
136 return NULL;
137 }
138
139 return hBitmap;
140}
141
142HBITMAP LoadPNGResource(HINSTANCE hInstance, LPCWSTR resourceName, LPCWSTR resourceType) {
143 if (!$WICConvertBitmapSource) {

Callers 2

LoadPNGResourceFunction · 0.85
LoadJPEGFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected