Click here to Skip to main content
11,481,843 members (63,863 online)
Click here to Skip to main content

Display PNG, JPG, etc. on Pocket PC

, 22 Sep 2002 CPOL 247.7K 955 53
Rate this:
Please Sign up or sign in to vote.
Combine CXImage and DibSectionLite on Pocket PC.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jim Koornneef
Web Developer Golden Crater Corp
Canada Canada
Jim is the President of Golden Crater Corp. (formerly Golden Crater Software) which produces:

Tiny eBook Reader - Read eBooks anywhere, on any web enabled device or phone.

Doberman BMS - Home Automation and Building Management System bridging and enhancing several automation hardware platforms.

Comments and Discussions

 
GeneralI'm trying to compile it for PPC 2003 with VS2005 and get a lot of errors Pin
WSQ11-Jul-10 22:50
memberWSQ11-Jul-10 22:50 
Generalit's complex、hard to use. and the autor didn't explain too much Pin
lanmanck6-Mar-09 4:19
memberlanmanck6-Mar-09 4:19 
GeneralLinker error on building PocketPCTest Pin
Avinash Sahay23-Apr-08 3:28
memberAvinash Sahay23-Apr-08 3:28 
GeneralDibSectionlite.cpp missing Pin
Avinash Sahay23-Apr-08 2:37
memberAvinash Sahay23-Apr-08 2:37 
QuestionHow to display in a given window? Pin
Avinash Sahay23-Apr-08 0:12
memberAvinash Sahay23-Apr-08 0:12 
AnswerRe: How to display in a given window? Pin
Avinash Sahay23-Apr-08 0:32
memberAvinash Sahay23-Apr-08 0:32 
GeneralI am trying to compile it under evc4 Pin
xnkjljlj20-Jan-08 6:57
memberxnkjljlj20-Jan-08 6:57 
GeneralI'm trying to compile it for PPC 2003 with VS2005 and get a lot of errors Pin
OwenBurnett1-Jan-08 11:56
memberOwenBurnett1-Jan-08 11:56 
GeneralTrying to compile under wince 4.2 Pin
Member 282429318-Dec-07 5:54
memberMember 282429318-Dec-07 5:54 
Generalneeded to add fclose on DIBSectionLite.cpp or else got file sharing error (open file handle) Pin
fatjimmy.com12-Apr-07 12:46
memberfatjimmy.com12-Apr-07 12:46 
Questionconvert .jpg to .bmp [modified] Pin
C#_Smurf23-Jan-07 5:16
memberC#_Smurf23-Jan-07 5:16 
GeneralCxImage Pocket PC Port [modified] Pin
Vincent_RICHOMME11-Apr-06 0:28
memberVincent_RICHOMME11-Apr-06 0:28 
GeneralRe: CxImage Pocket PC Port Pin
dmig1-Jun-06 5:59
memberdmig1-Jun-06 5:59 
GeneralRe: CxImage Pocket PC Port Pin
Vincent_RICHOMME23-Aug-06 11:10
memberVincent_RICHOMME23-Aug-06 11:10 
GeneralRe: CxImage Pocket PC Port Pin
hchlqlz15-Oct-07 17:49
memberhchlqlz15-Oct-07 17:49 
GeneralRe: CxImage Pocket PC Port Pin
Vincent_RICHOMME16-Oct-07 0:06
memberVincent_RICHOMME16-Oct-07 0:06 
GeneralRe: CxImage Pocket PC Port Pin
yunf25-Nov-09 23:07
memberyunf25-Nov-09 23:07 
GeneralCXImage Pin
BertvR6-Mar-06 8:43
memberBertvR6-Mar-06 8:43 
GeneralI couldn't download the Source file Pin
smartslack15-Dec-05 0:30
membersmartslack15-Dec-05 0:30 
GeneraleVC++ with SP4 Pin
Alper KARS23-Jun-05 23:53
memberAlper KARS23-Jun-05 23:53 
AnswerRe: eVC++ with SP4 Pin
Fabio Falsini28-Nov-05 5:33
memberFabio Falsini28-Nov-05 5:33 
QuestionHow to load large JPG files? Pin
cxf197629-Mar-05 21:43
membercxf197629-Mar-05 21:43 
AnswerRe: How to load large JPG files? Pin
cxf197629-Mar-05 21:45
membercxf197629-Mar-05 21:45 
GeneralRe: How to load large JPG files? Pin
cxf197629-Mar-05 23:17
membercxf197629-Mar-05 23:17 
AnswerRe: How to load large JPG files? Pin
yangmingtao14-Mar-07 18:19
memberyangmingtao14-Mar-07 18:19 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 23 Sep 2002
Article Copyright 2002 by Jim Koornneef
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid