Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > General Discussion
  New Posts New Posts RSS Feed - How i can render PNG image
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How i can render PNG image

 Post Reply Post Reply
Author
Message
shobits1 View Drop Down
Newbie
Newbie
Avatar

Joined: 18 June 2007
Location: Algeria
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote shobits1 Quote  Post ReplyReply Direct Link To This Post Topic: How i can render PNG image
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
shobits1 View Drop Down
Newbie
Newbie
Avatar

Joined: 18 June 2007
Location: Algeria
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote shobits1 Quote  Post ReplyReply Direct Link To This Post 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...
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
shobits1 View Drop Down
Newbie
Newbie
Avatar

Joined: 18 June 2007
Location: Algeria
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote shobits1 Quote  Post ReplyReply Direct Link To This Post 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  danpetitt
 
 
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) );
 
 
}
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
shobits1 View Drop Down
Newbie
Newbie
Avatar

Joined: 18 June 2007
Location: Algeria
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote shobits1 Quote  Post ReplyReply Direct Link To This Post 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
 
 
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.
 
 
 
 
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
shobits1 View Drop Down
Newbie
Newbie
Avatar

Joined: 18 June 2007
Location: Algeria
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote shobits1 Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2007 at 3:31pm
Thank's oleg ....
 
I try it and it work...
 
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.