diff --git a/src/Magpie.App/IconHelper.cpp b/src/Magpie.App/IconHelper.cpp index 9d919f92..17d265e1 100644 --- a/src/Magpie.App/IconHelper.cpp +++ b/src/Magpie.App/IconHelper.cpp @@ -57,7 +57,7 @@ static SoftwareBitmap HIcon2SoftwareBitmap(HICON hIcon) { { BitmapBuffer buffer = bitmap.LockBuffer(BitmapBufferAccessMode::Write); uint8_t* pixels = buffer.CreateReference().data(); - + if (!CopyPixelsOfHBmp(iconInfo.hbmColor, bmp.bmWidth, bmp.bmHeight, pixels)) { return nullptr; } @@ -83,29 +83,27 @@ static SoftwareBitmap HIcon2SoftwareBitmap(HICON hIcon) { pixels[i + 1] = (uint8_t)std::lroundf(pixels[i + 1] * alpha); pixels[i + 2] = (uint8_t)std::lroundf(pixels[i + 2] * alpha); } - } else { + } else if (iconInfo.hbmMask) { // 彩色掩码图标 - if (iconInfo.hbmMask) { - std::unique_ptr maskData = std::make_unique(pixelsSize); - if (!CopyPixelsOfHBmp(iconInfo.hbmMask, bmp.bmWidth, bmp.bmHeight, maskData.get())) { - return nullptr; - } + std::unique_ptr maskData = std::make_unique(pixelsSize); + if (!CopyPixelsOfHBmp(iconInfo.hbmMask, bmp.bmWidth, bmp.bmHeight, maskData.get())) { + return nullptr; + } - for (uint32_t i = 0; i < pixelsSize; i += 4) { - // hbmMask 表示是否应用掩码 - // 如果需要应用掩码而掩码不为零,那么这个图标无法转换为彩色图标,这种情况下直接忽略掩码 - if (maskData[i] != 0 && pixels[i] == 0 && pixels[i + 1] == 0 && pixels[i + 2] == 0) { - // 掩码全为 0 表示透明像素 - std::memset(pixels + i, 0, 4); - } else { - pixels[i + 3] = 255; - } - } - } else { - for (uint32_t i = 3; i < pixelsSize; i += 4) { - pixels[i] = 255; + for (uint32_t i = 0; i < pixelsSize; i += 4) { + // hbmMask 表示是否应用掩码 + // 如果需要应用掩码而掩码不为零,那么这个图标无法转换为彩色图标,这种情况下直接忽略掩码 + if (maskData[i] != 0 && pixels[i] == 0 && pixels[i + 1] == 0 && pixels[i + 2] == 0) { + // 掩码全为 0 表示透明像素 + std::memset(pixels + i, 0, 4); + } else { + pixels[i + 3] = 255; } } + } else { + for (uint32_t i = 3; i < pixelsSize; i += 4) { + pixels[i] = 255; + } } }