Click here to Skip to main content

Alain Rist - Professional Profile

16,978
Author
7,420
Authority
279
Debator
253
Editor
8
Enquirer
530
Organiser
1,512
Participant
22 Feb 2010: Best C++/MFC article of January 2010
21 Oct 2009: Code Lean and Mean
29 Nov 2007: Best C++/MFC article of November 2007
No Biography provided
Member since Sunday, January 5, 2003 (9 years, 4 months)

For more information on Reputation please see the FAQ.
 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
  Refresh
GeneralUsing a single PNG resource for WinMobile apps [modified] Pin
Sunday, April 19, 2009 8:58 PM
On http://nativemobile.blogspot.com/[^] there is a discussion on using png images with alpha transparency on mobile devices.
 
This is what I use to build all the images needed at all sizes and resolutions from a single PNG resource. The PNG resource MUST be of type "GIF" D'Oh! | :doh: to be loaded by ::SHLoadImageResource().
 
Of course, requires WTL Smile | :)
 
More in my next CP Mobile article, don't ask me when Laugh | :laugh: .
 
inline HIMAGELIST AtlLoadImageList(UINT uID, int cy, UINT uFlags = ILC_COLOR32)
{
	// Load uID PNG image strip resource 
	CBitmap bmpOrig = ::SHLoadImageResource(ModuleHelper::GetResourceInstance(), uID);
	ATLASSERT(!bmpOrig.IsNull());
	CSize sizeOrig;
	bmpOrig.GetSize(sizeOrig);
 
	// Size to request
	INT n = sizeOrig.cx / sizeOrig.cy,
		cx = cy * n;
	CBitmap bmp;
	DRA::ImageList_StretchBitmap(bmpOrig, &bmp.m_hBitmap, cx, cy, n, 1);
 
	// Create ImageList
	CImageList iml;
	iml.Create(cx, cy, uFlags, n, 0);
	iml.Add(bmp.IsNull() ? bmpOrig : bmp);
	return iml;
}
Actually ::SHLoadImageResource() loads the PNG as a 16bits DIB (native DDB format), so alpha is lost before the call to DRA::ImageList_StretchBitmap().
 
This is not always a problem, as all with end up as a 16bits DDB on the device graphic chip, but it may be if we need further manipulations with transparency.
 
Soon coming my Image component which addresses that issue.
 
cheers,
AR
 
modified on Saturday, April 25, 2009 5:26 AM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 28 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid