Print Page | Close Window

How i can render PNG image

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=7402
Printed Date: 25 June 2024 at 10:23pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How i can render PNG image
Posted By: shobits1
Subject: How i can render PNG image
Date Posted: 18 June 2007 at 10:51pm
I wonder if any body can help to use codejock for loading and rendering PNG images from ressource and from external file.
 
I try diffrent function from codejock but no help,,
I excepet to show me the best why to draw a PNG image (storred
internally in my exe, or storred in extern dll file), and where i must store my PNG image( where in the ressource under "PNG" or under "Bitmap" Group).

 
sorry for my bad english,,, and thanks



Replies:
Posted By: Oleg
Date Posted: 19 June 2007 at 1:26am
Hello,
 
Try this
 
CXTPGraphicBitmapPng bitmap;
bitmap.LoadFromResource(hModule, hRes);
 
or load bitmaps/draw using CXTPImageManager collection


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 19 June 2007 at 11:28pm
Thank's "oleg"...
 
I will try with CXTPGraphicBitmapPng.
 
An other question: where my PNG image suppos to be in my resource file, I mean  like icons it must be under ICON group & bitmap image must be under BITAMP group in my resource and so on (where PNG image must be). I try to set it under PNG group but it doesn't wok.
 
thank's for your help...


Posted By: Oleg
Date Posted: 20 June 2007 at 1:25am
Yes, you need PNG group.
 
check Samples\CommandBars\ActionsSample  sample. It uses png for toolbar icons:
 
IDR_MAINFRAME           PNG     MOVEABLE PURE   "res\\Toolbar.png"
 
 
Here part of code from sources:
 
hModule = AfxFindResourceHandle(lpszResource, _T("PNG"));
 BOOL bPngBitmap = IsPngBitmapResource(hModule, lpszResource);
 if (bPngBitmap)
 {
  CXTPGraphicBitmapPng bmpIcons;
  HRSRC hResource = ::FindResource(hModule, lpszResource, _T("PNG"));
  if (!bmpIcons.LoadFromResource(hModule, hResource))
   return NULL;
  if (lbAlphaBitmap)
  {
   *lbAlphaBitmap = bmpIcons.IsAlpha();
  }
  return (HBITMAP)bmpIcons.Detach();
 }


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 20 June 2007 at 8:00pm
Thank's again oleg...
I have used this code and it works for load PNG image from file or from resource
 
---- Load PNG from local file
 
 
BOOL bAlpha=0;
HBITMAP hb = CXTPImageManagerIcon::LoadBitmapFromFile (pszFilePng, &bAlpha); 
 
---- Load PNG from resource
 
BOOL bAlpha = FALSE;
hb = CXTPImageManagerIcon::LoadBitmapFromResource(_T("IDB_PNG_IMAGE"),&bAlpha );
     
LPCTSTR lpszResource = MAKEINTRESOURCE(IDB_PNG_IMAGE);
HMODULE hModule = AfxFindResourceHandle( lpszResource, _T("PNG") );
     
BOOL bPngBitmap = CXTPImageManagerIcon::IsPngBitmapResource(hModule, lpszResource);
if (bPngBitmap)
{
      CXTPGraphicBitmapPng bmpIcons;
      HRSRC hResource = ::FindResource(hModule, lpszResource, _T("PNG"));
 
       if (!bmpIcons.LoadFromResource(hModule, hResource))
             TRACE0("Can't Load");
       
 BOOL lbAlphaBitmap = bmpIcons.IsAlpha();
 
 hb = (HBITMAP)bmpIcons.Detach();
}
 
Thanks to oleg
---- Also I found a post and I verified it and it work,, thanks to   http://forum.codejock.com/member_profile.asp?PF=1322&FID=18 - danpetitt
http://forum.codejock.com/forum_posts.asp?TID=5840 - http://forum.codejock.com/forum_posts.asp?TID=5840
 
 
The Problem is the look of my render; it doesn't draw the transparency in the right way
 
This my PNG render.
 
This windows XP Picture and Fax preview render
 
n  I used to render my image this code
void CChildView::OnPaint()
{
      CPaintDC pdc(this); // device context for painting
      CXTMemDC dc(&pdc, CRect(0,0,0,0)); // I used this to reduce filcker
     
CXTPImageManagerIcon::DrawAlphaBitmap(&dc, hb, CPoint(50,50), CSize(256,256), 0, CSize(256,256) );
 
 
}


Posted By: Oleg
Date Posted: 21 June 2007 at 1:26am
Hi,
Attach project with all bitmaps/png here or in issue track.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 21 June 2007 at 11:36am

Hi oleg ....

since I can't upload my project, I have created a simple one that demonstrate the problem
this is the link
 
http://forum.codejock.com/uploads/20070621_113016_Draw_PNG.rar - uploads/20070621_113016_Draw_PNG.rar
 
the project was create with VS2005
the file "ChildView.cpp" have my routine to load and draw the PNG image.
 
you can check my code, and I hope to figureout where I am wrong...
 
Thank's to you for help.
 
 
 
 


Posted By: Oleg
Date Posted: 21 June 2007 at 3:03pm
Right. You also need premultiply bitmap if it has alpha layer:
 

RSRC hResource = ::FindResource(hModule, lpszResource, _T("PNG"));

CXTPGraphicBitmapPng mBitmapPng;

if (!mBitmapPng.LoadFromResource(hModule, hResource))

TRACE0("\nCan't Load PNG from resource\n");

mBitmap.Attach(CXTPImageManagerIcon::PreMultiplyAlphaBitmap(mBitmapPng));

CXTPImageManagerIcon::DrawAlphaBitmap( &dc, mBitmap, CPoint(50,50), CSize(256,256), 0, CSize(256,256) );

 



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 21 June 2007 at 3:31pm
Thank's oleg ....
 
I try it and it work...
 
 



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net