]> OCCT Git - occt.git/commitdiff
0029184: Visualization - DrawWindow::Save() fails when using WinCodec with PNG codec
authorkgv <kgv@opencascade.com>
Wed, 13 Sep 2017 15:12:57 +0000 (17:12 +0200)
committerbugmaster <bugmaster@opencascade.com>
Fri, 6 Oct 2017 07:28:21 +0000 (10:28 +0300)
DrawWindow::Save() now uses Image_Format_BGR instead of Image_Format_BGR32
for better compatibility with image encoders when dumping WinAPI bitmap.

src/Draw/Draw_Window.cxx

index 2d9f799bed920b2e8e78c8e2f7abb10cf745fe2d..2fac12bc88ae3568ca83e18debb91114f35e2333 100644 (file)
@@ -1795,8 +1795,8 @@ static Standard_Boolean SaveBitmap (HBITMAP     theHBitmap,
   }
 
   Image_AlienPixMap anImage;
-  const Standard_Size aSizeRowBytes = Standard_Size(aBitmap.bmWidth) * 4;
-  if (!anImage.InitTrash (Image_Format_BGR32, Standard_Size(aBitmap.bmWidth), Standard_Size(aBitmap.bmHeight), aSizeRowBytes))
+  const Standard_Size aSizeRowBytes = ((Standard_Size(aBitmap.bmWidth) * 24 + 31) / 32) * 4; // 4 bytes alignment for GetDIBits()
+  if (!anImage.InitTrash (Image_Format_BGR, Standard_Size(aBitmap.bmWidth), Standard_Size(aBitmap.bmHeight), aSizeRowBytes))
   {
     return Standard_False;
   }
@@ -1809,7 +1809,7 @@ static Standard_Boolean SaveBitmap (HBITMAP     theHBitmap,
   aBitmapInfo.biWidth       = aBitmap.bmWidth;
   aBitmapInfo.biHeight      = aBitmap.bmHeight; // positive means bottom-up!
   aBitmapInfo.biPlanes      = 1;
-  aBitmapInfo.biBitCount    = 32; // use 32bit for automatic word-alignment per row
+  aBitmapInfo.biBitCount    = 24;
   aBitmapInfo.biCompression = BI_RGB;
 
   // Copy the pixels