<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : [BUG] CXTPGraphicBitmapPng [UPDATED - 22-o9-2o11]</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Toolkit Pro : [BUG] CXTPGraphicBitmapPng [UPDATED - 22-o9-2o11]]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Tue, 09 Jun 2026 03:59:55 +0000</pubDate>
  <lastBuildDate>Fri, 16 Sep 2011 16:53:36 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=18959</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[[BUG] CXTPGraphicBitmapPng [UPDATED - 22-o9-2o11] :       First:    HBITMAP...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=18959&amp;PID=66333&amp;title=bug-cxtpgraphicbitmappng-updated-22o92o11#66333</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=6515">tomay3000</a><br /><strong>Subject:</strong> 18959<br /><strong>Posted:</strong> 16 September 2011 at 4:53pm<br /><br /><font size="5"><b>First:</b></font><b><br>  <br>HBITMAP CXTPGraphicBitmapPng::ConvertToBitmap(BYTE* pbImage, CSize szImage,&nbsp; int cImgChannels) const<br>{<br>  <br>.<br>.<br>.<br>  <br>bmi.bmiHeader.biBitCount = 32;&nbsp;&nbsp; <font size="3" color="#FF0000">// Here the destination bitmap will be created 32bits even the source png is not 32bits.</font><br>  <br>.<br>.<br>.<br>  <br>// copy image to screen<br>  <br>&nbsp;&nbsp; &nbsp;for (yImg = 0; yImg &lt; szImage.cy; yImg++)<br>&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;src = pbImage + yImg * wImgRowBytes;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dst = pBits + yImg * wDIRowBytes;<br>  <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for (xImg = 0; xImg &lt; szImage.cx; xImg++)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;r = *src++;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;g = *src++;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b = *src++;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;*dst++ = b;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;*dst++ = g;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;*dst++ = r;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;a = 0;<br>  <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (cImgChannels == 4)&nbsp;&nbsp; <font size="3" color="#FF0000">// Else </font></b><b>(cImgChannels != 4)</b><b><font size="3" color="#FF0000">, a = 0, so all the destination bitmap alpha bytes will be 0 (the destination bitmap will draw transparent).</font><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;a = *src++;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;*dst++ = a;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;}<br>  <br>.<br>.<br>.<br>  <br>}<br>  <br>And</b> a call to the function<b><br>  <br>BOOL CXTPGraphicBitmapPng::LoadFromFile(CFile* pFile)<br>{<br>  <br>.<br>.<br>.<br>  <br>m_bAlpha = (cImgChannels == 4);&nbsp;&nbsp; <font size="3" color="#FF0000">// Asumming</font> </b><b>(cImgChannels != 4)<font size="3" color="#FF0000">.</font></b> <font size="3"><b><font color="#FF0000">So</font></b></font> <b>m_bAlpha = FALSE<font size="3" color="#FF0000">.<br>  </font></b><b><font size="3" color="#FF0000"><br>  </font>.<br>.<br>.<br>  <br>}</b><br><br><b>Will</b> cause<b><br>  <br>AFX_INLINE BOOL CXTPGraphicBitmapPng::IsAlpha() const {<br>&nbsp;&nbsp; &nbsp;return m_bAlpha;<br>}<br>  <br>returning <font color="#FF0000"><font size="3">FALSE</font>,</font> and actually<br></b><b>bmi.bmiHeader.biBitCount = 32;&nbsp;&nbsp; <font size="3" color="#FF0000">// The destination bitmap is created 32bits</font></b>.<br><img src="http://forum.codejock.com/smileys/smiley21.gif" border="0" alt="Thumbs Down" title="Thumbs Down" /><br>=======================================================<br><font size="5"><b><br>Second:</b></font><br><br><b>HBITMAP AFX_CDECL CXTPImageManagerIcon::LoadBitmapFromFile(LPCTSTR lpszFileName, BOOL* lbAlphaBitmap)<br>{<br>  <br>.<br>.<br>.<br>  <br>HBITMAP hBmp = (HBITMAP)LoadImage(0, lpszFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | (bAlphaBitmap ? LR_CREATEDIBSECTION : 0) | LR_LOADFROMFILE);&nbsp;&nbsp; <font size="3" color="#FF0000">//</font></b><b> </b><b>LoadImage</b> <b><font size="3" color="#FF0000">here is always returning 32bits bitmaps even they are 24, 16, 8, 4 or monochrome.</font></b> <img src="http://forum.codejock.com/smileys/smiley21.gif" border="0" alt="Thumbs Down" title="Thumbs Down" /><br><b><br>.<br>.<br>.<br>  <br>}<br><br></b><b>LoadImage </b>is working right outside <b>CXTPImageManagerIcon::LoadBitmapFromFile </b>function <img src="http://forum.codejock.com/smileys/smiley20.gif" border="0" alt="Thumbs Up" title="Thumbs Up" /><br><br>The same problem about <b>LoadImage </b>function for the below functions:<br><br><b>HBITMAP AFX_CDECL CXTPImageManagerIcon::LoadBitmapFromResource(LPCTSTR lpszResource, BOOL* lbAlphaBitmap)<br><br>HBITMAP AFX_CDECL CXTPImageManagerIcon::LoadBitmapFromResource(HMODULE hModule, LPCTSTR lpszResource, BOOL* lbAlphaBitmap)</b><br><br><font size="5"><b>Finally:<br></b></font><b><br></b>This is the correct<b> </b><b>CXTPGraphicBitmapPng::ConvertToBitmap </b>function that should be<br><span style="font-weight: bold;"></span><br><b>HBITMAP CXTPGraphicBitmapPng::ConvertToBitmap(LPBYTE lpbytImage, CSize szImage, int iImgChannels) const<br>{<br>&nbsp;&nbsp;&nbsp; BITMAPINFO bmi;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // Initialize header to 0s.<br>&nbsp;&nbsp;&nbsp; ::ZeroMemory(&amp;bmi, sizeof(BITMAPINFO));<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // Fill out the fields you care about.<br>&nbsp;&nbsp;&nbsp; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br>&nbsp;&nbsp;&nbsp; bmi.bmiHeader.biWidth = szImage.cx;<br>&nbsp;&nbsp;&nbsp; bmi.bmiHeader.biHeight = -szImage.cy;<br>&nbsp;&nbsp;&nbsp; bmi.bmiHeader.biPlanes = 1;<br>&nbsp;&nbsp;&nbsp; bmi.bmiHeader.biBitCount = <font size="3" color="#FF0000">(WORD)(iImgChannels == 4 ? 32 : 24);</font><br>&nbsp;&nbsp;&nbsp; bmi.bmiHeader.biCompression = BI_RGB;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; HBITMAP hBitmap;<br>&nbsp;&nbsp;&nbsp; LPBYTE lpbytBits;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; hBitmap = ::CreateDIBSection(::CreateCompatibleDC(NULL), &amp;bmi, DIB_RGB_COLORS, (LPVOID*)&amp;lpbytBits, NULL, 0);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if (hBitmap == NULL)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return NULL;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // Copy image<br>&nbsp;&nbsp;&nbsp; LPBYTE lpbytSrc, lpbytDst;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; lpbytSrc = lpbytImage;<br>&nbsp;&nbsp;&nbsp; lpbytDst = lpbytBits;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; szImage.cy; i ++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; szImage.cx; j ++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytDst&#091;0&#093; = lpbytSrc&#091;2&#093;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytDst&#091;1&#093; = lpbytSrc&#091;1&#093;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytDst&#091;2&#093; = lpbytSrc&#091;0&#093;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (iImgChannels == 4)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytDst&#091;3&#093; = lpbytSrc&#091;3&#093;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytSrc += iImgChannels;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytDst += iImgChannels;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (iImgChannels == 3)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lpbytDst += <font size="3" color="#FF0000">-(szImage.cx * 3) &amp; 3;</font><br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return hBitmap;<br>}<br><br>And</b> the <b>LoadImage </b>implementation that should be<br><b><br>(HBITMAP)::LoadImage(NULL, lpszFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);&nbsp;&nbsp;<font size="3" color="#FF0000"> // For files.</font></b><br><b><br>And<br><br>(HBITMAP)::LoadImage(hModule, lpszResource, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);&nbsp;&nbsp; <font size="3" color="#FF0000">// For resources.</font><br><br>Thank you for your understand ;)</b><br>]]>
   </description>
   <pubDate>Fri, 16 Sep 2011 16:53:36 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=18959&amp;PID=66333&amp;title=bug-cxtpgraphicbitmappng-updated-22o92o11#66333</guid>
  </item> 
 </channel>
</rss>