Skip to content

Commit 4f0d131

Browse files
committed
fix: empty image
1 parent 1a1837d commit 4f0d131

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/winicon.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,19 @@ void SaveBitmapAsPNG(HBITMAP hBitmap, const std::wstring& outputPath) {
7272

7373
Bitmap bitmap(bm.bmWidth, bm.bmHeight, PixelFormat32bppARGB);
7474

75-
BitmapData bmpData;
75+
Gdiplus::BitmapData bmpData;
7676
Rect rect(0, 0, bm.bmWidth, bm.bmHeight);
7777

7878
if (bitmap.LockBits(&rect, ImageLockModeWrite, PixelFormat32bppARGB, &bmpData) == Ok) {
7979
int bytesPerPixel = 4;
80-
BYTE* destData = static_cast<BYTE*>(bmpData.Scan0);
81-
82-
HDC hdc = GetDC(nullptr);
83-
GetDIBits(hdc, hBitmap, 0, bm.bmHeight, destData, (BITMAPINFO*)&bm, DIB_RGB_COLORS);
84-
ReleaseDC(nullptr, hdc);
80+
BYTE* srcData = (BYTE*)bm.bmBits;
81+
BYTE* destData = (BYTE*)bmpData.Scan0;
82+
83+
for (int y = 0; y < bm.bmHeight; y++) {
84+
BYTE* srcRow = srcData + (bm.bmHeight - 1 - y) * bm.bmWidth * bytesPerPixel;
85+
BYTE* destRow = destData + y * bmpData.Stride;
86+
memcpy(destRow, srcRow, bm.bmWidth * bytesPerPixel);
87+
}
8588

8689
bitmap.UnlockBits(&bmpData);
8790
}

0 commit comments

Comments
 (0)