Click here to Skip to main content
6,304,948 members and growing! (18,625 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Graphics and Multimedia     Intermediate

Display PNG, JPG, etc on PocketPC

By Jim Koornneef

Combine CXImage and DibSectionLite on PocketPC
VC6, VC7, Windows, PocketPC 2002, MFC, Dev
Posted:22 Sep 2002
Views:173,768
Bookmarked:44 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
22 votes for this article.
Popularity: 6.15 Rating: 4.58 out of 5
2 votes, 12.5%
1

2

3
1 vote, 6.3%
4
13 votes, 81.3%
5

Introduction

In doing quite a bit of work with a PocketPC home automation client, I needed a way to display user-defined images in the device.

I found some very good and useful code out there in CodeProject and was able to combine them (with some modifications and enhancements) into group of very useful libraries.

I won't go into too many details, as I've basically taken Chris Maunder's DibSectionLite and added methods to load using Davide Pizzolato's CXImage classes. You can find their original libraries and documentation on this site. No point in replicating it here.

Details

Most of the work was in taking the original CXImage library and modifying it to make it compile on the PocketPC (Using eVC 3.0) This required a few #define changes and #ifdef out any try...catch code. I opted to return false.

The next step was debugging the PNG code. Since the PNG library uses function pointers, it turns out that eVC modifies the signature between a debug and release build. The stack becomes corrupt upon return unless the signature for these functions are modified as below:

#if defined (_WIN32_WCE) && !defined (_DEBUG)
	#define _CDECL_MODE_	__cdecl
#else
	#define _CDECL_MODE_	
#endif

static void _CDECL_MODE_ user_write_data(png_structp png_ptr, 
                                         png_bytep data, 
                                         png_size_t length)
Finally, I modified DibSectionLite to include:
  • All the suggested fixes posted on CodeProject (including 16, 24 bit images)
  • Cropping. I have a floorplan image I need to pan around on the screen, cropping is quite fast when displaying only a portion of the image.
  • Original Load and Save now take a CFile or CString.. Useful for memory images (CMemFile)
  • Loading images via CXImage.

You can add support and shrink/expand you executable size based on these defines as well as the ones in CXImage:

#define DIBSECTION_SUPPORT_BMP 1
#define DIBSECTION_SUPPORT_GIF 1    // Patented! 

#define DIBSECTION_SUPPORT_JPG 1
#define DIBSECTION_SUPPORT_PNG 1
//#define DIBSECTION_SUPPORT_MNG 0  // Orig. Lib disabled this

#define DIBSECTION_SUPPORT_ICO 1
//#define DIBSECTION_SUPPORT_TIF 0  // Patented!   //too many problems with 

                                    // __cdecl, see header  //jk

#define DIBSECTION_SUPPORT_TGA 1
#define DIBSECTION_SUPPORT_PCX 1
//#define DIBSECTION_SUPPORT_WBMP 0 //totally corrupt image... This might 

                                    // take some work.  //jk 

//#define DIBSECTION_SUPPORT_WMF 0  // WMF and PocketPC don't go hand-in hand 

                                    // too well (GetEnhMetaFilePaletteEntries 

                                    // unsupported by the OS).

//#define DIBSECTION_SUPPORT_J2K 0  // Beta  //totally corrupt image... This 

                                    //might take some work. //jk

#define DIBSECTION_SUPPORT_JBG 1    // Patented! see ../jbig/patents.htm    


New methods for loading are as follows:
BOOL LoadPNG(LPCTSTR lpszFileName);
BOOL LoadJPG(LPCTSTR lpszFileName);
BOOL LoadBMP(LPCTSTR lpszFileName);
BOOL LoadGIF(LPCTSTR lpszFileName);
BOOL LoadMNG(LPCTSTR lpszFileName);
BOOL LoadICO(LPCTSTR lpszFileName);
BOOL LoadTIF(LPCTSTR lpszFileName);
BOOL LoadTGA(LPCTSTR lpszFileName);
BOOL LoadPCX(LPCTSTR lpszFileName);
BOOL LoadWBMP(LPCTSTR lpszFileName);
BOOL LoadWMF(LPCTSTR lpszFileName);
BOOL LoadJ2K(LPCTSTR lpszFileName);
BOOL LoadJBG(LPCTSTR lpszFileName);
The code unravels and builds as a bunch of .LIB

You can compile and build the PocketPCTest app for your device. It is nothing fancy. Simply an exerciser. Uncomment the line in PocketPCTestView.cpp as needed.

The test app includes a definition of:

CDIBSectionLite	m_image;
in the header.

To Draw:

void CPocketPCTestView::OnDraw(CDC* pDC)
{
	CPocketPCTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here

	
	m_image.Draw(pDC, CPoint(0,0));

}
And to load:
CPocketPCTestView::CPocketPCTestView()
{
	// TODO: add construction code here


	m_image.LoadPNG(_T("\\test.png"));	// 24bit OK

//	m_image.LoadPNG(_T("\\test-pal.png"));	// 256 OK

//	m_image.LoadJPG(_T("\\test.JPG"));	//ok

//	m_image.LoadBMP(_T("\\test.BMP"));	//ok

//	m_image.LoadGIF(_T("\\test.GIF"));	//ok

//	m_image.LoadICO(_T("\\test.ICO"));	//ok

//	m_image.LoadTGA(_T("\\test.TGA"));	//ok

//	m_image.LoadPCX(_T("\\test.PCX"));	//ok

//	m_image.LoadJBG(_T("\\test.JBG"));	//ok

	
// This wasn't in the original code.

////	m_image.LoadMNG(_T("\\test.MNG"));	


// WMF and PocketPC don't go hand-in hand too well (GetEnhMetaFilePaletteEntries 

// unsupported by the OS).

////	m_image.LoadWMF(_T("\\test.WMF"));	


// too many problems with __cdecl, see header

////	m_image.LoadTIF(_T("\\test.TIF"));	


// totally corrupt image... This might take some work.

////	m_image.LoadWBMP(_T("\\test.WBMP"));


// totally corrupt image... This might take some work.

////	m_image.LoadJ2K(_T("\\test.J2K"));	


}
That's about it. I didn't really spend much time with making J2K, TIF, and WBMP work. I'll update the article if someone gets them working.

Chris and Davide, as well as those that have contributed to their articles. Many thanks! I hope some of these changes/fixes might make it back into your original libraries so us PocketPC developers can use your code 'out of the box'.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jim Koornneef


Member
Jim's pet project is epAssist which is a natural language interface to a AppBar on the desktop and email, effectively creating an electronic assistant you can direct over email or on-screen, with speech recognition under research.

After releasing the SDK, allowing others to extend their application with language support, he felt it was time to give more back to the community by writing up some articles on tips picked up along the way.

Occupation: Web Developer
Location: Canada Canada

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 75 (Total in Forum: 75) (Refresh)FirstPrevNext
Generalit's complex、hard to use. and the autor didn't explain too much Pinmemberlanmanck4:19 6 Mar '09  
GeneralLinker error on building PocketPCTest PinmemberAvinash Sahay3:28 23 Apr '08  
GeneralDibSectionlite.cpp missing PinmemberAvinash Sahay2:37 23 Apr '08  
GeneralHow to display in a given window? PinmemberAvinash Sahay0:12 23 Apr '08  
GeneralRe: How to display in a given window? PinmemberAvinash Sahay0:32 23 Apr '08  
GeneralI am trying to compile it under evc4 Pinmemberxnkjljlj6:57 20 Jan '08  
GeneralI'm trying to compile it for PPC 2003 with VS2005 and get a lot of errors PinmemberOwenBurnett11:56 1 Jan '08  
GeneralTrying to compile under wince 4.2 PinmemberMember 28242935:54 18 Dec '07  
Generalneeded to add fclose on DIBSectionLite.cpp or else got file sharing error (open file handle) Pinmemberfatjimmy.com12:46 12 Apr '07  
Questionconvert .jpg to .bmp [modified] PinmemberC#_Smurf5:16 23 Jan '07  
GeneralCxImage Pocket PC Port [modified] PinmemberVincent_RICHOMME0:28 11 Apr '06  
GeneralRe: CxImage Pocket PC Port Pinmemberdmig5:59 1 Jun '06  
GeneralRe: CxImage Pocket PC Port PinmemberVincent_RICHOMME11:10 23 Aug '06  
GeneralRe: CxImage Pocket PC Port Pinmemberhchlqlz17:49 15 Oct '07  
GeneralRe: CxImage Pocket PC Port PinmemberVincent_RICHOMME0:06 16 Oct '07  
GeneralCXImage PinmemberBertvR8:43 6 Mar '06  
GeneralI couldn't download the Source file Pinmembersmartslack0:30 15 Dec '05  
GeneraleVC++ with SP4 PinmemberAlper KARS23:53 23 Jun '05  
AnswerRe: eVC++ with SP4 PinmemberFabio Falsini5:33 28 Nov '05  
GeneralHow to load large JPG files? Pinmembercxf197621:43 29 Mar '05  
GeneralRe: How to load large JPG files? Pinmembercxf197621:45 29 Mar '05  
GeneralRe: How to load large JPG files? Pinmembercxf197623:17 29 Mar '05  
GeneralRe: How to load large JPG files? Pinmemberyangmingtao18:19 14 Mar '07  
GeneralHow to make alpha blending work for png files in wince? PinmemberDani10000114:18 3 Jan '05  
GeneralRe: How to make alpha blending work for png files in wince? PinmemberDani10000116:42 3 Jan '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Sep 2002
Editor: Chris Maunder
Copyright 2002 by Jim Koornneef
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project