Click here to Skip to main content
15,890,438 members
Articles / Mobile Apps / Windows Mobile

Display PNG, JPG, etc. on Pocket PC

Rate me:
Please Sign up or sign in to vote.
4.94/5 (16 votes)
22 Sep 2002CPOL2 min read 466.1K   1.2K   53   79
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)


Written By
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

 
AnswerRe: anyone ran it on ARM? Pin
zhangzq7126-Aug-03 16:47
zhangzq7126-Aug-03 16:47 
GeneralProblems while compiling Pin
\SOLMAN3-Jun-03 4:24
\SOLMAN3-Jun-03 4:24 
GeneralRe: Problems while compiling Pin
\SOLMAN4-Jun-03 5:42
\SOLMAN4-Jun-03 5:42 
GeneralRe: Problems while compiling Pin
akhella6-Jun-03 19:58
akhella6-Jun-03 19:58 
GeneralRe: Problems while compiling Pin
\SOLMAN11-Jun-03 3:27
\SOLMAN11-Jun-03 3:27 
GeneralRe: Problems while compiling Pin
faltu_app25-Jul-03 23:31
faltu_app25-Jul-03 23:31 
GeneralRe: Problems while compiling Pin
\SOLMAN1-Mar-04 23:11
\SOLMAN1-Mar-04 23:11 
GeneralRe: Problems while compiling Pin
mountainpeak25-Jan-05 15:08
mountainpeak25-Jan-05 15:08 
GeneralRe: Problems while compiling Pin
\SOLMAN25-Jan-05 20:21
\SOLMAN25-Jan-05 20:21 
GeneralRe: Problems while compiling Pin
cxf197624-Mar-05 16:24
cxf197624-Mar-05 16:24 
GeneralRe: Problems while compiling Pin
cxf197624-Mar-05 16:26
cxf197624-Mar-05 16:26 
Generalcan't compile Pin
conterra29-Apr-03 2:13
conterra29-Apr-03 2:13 
GeneralRe: can't compile Pin
mihcaoj11-May-03 6:48
mihcaoj11-May-03 6:48 
GeneralRe: Another way to use this class Pin
zanling25-May-03 23:22
zanling25-May-03 23:22 
GeneralI can't compile it Pin
Vincent Richomme3-Mar-03 22:34
Vincent Richomme3-Mar-03 22:34 
GeneralRe: I can't compile it Pin
Jim Koornneef12-Mar-03 2:46
Jim Koornneef12-Mar-03 2:46 
GeneralRe: I can't compile it Pin
Davide Pizzolato24-Apr-03 22:22
Davide Pizzolato24-Apr-03 22:22 
QuestionTIFF? Pin
Brian Heilman21-Jan-03 6:10
Brian Heilman21-Jan-03 6:10 
AnswerRe: TIFF? Pin
Ted Ferenc21-Jan-03 6:46
Ted Ferenc21-Jan-03 6:46 
GeneralErrata - Sorry! Pin
Ted Ferenc21-Jan-03 6:48
Ted Ferenc21-Jan-03 6:48 
GeneralRe: TIFF? Pin
Brian Heilman21-Jan-03 6:52
Brian Heilman21-Jan-03 6:52 
GeneralRe: TIFF? Pin
Ted Ferenc21-Jan-03 12:40
Ted Ferenc21-Jan-03 12:40 
GeneralThanks Pin
vantassel30-Dec-02 10:21
vantassel30-Dec-02 10:21 
GeneralExcellent work! But ... Pin
TomPeakz1-Dec-02 21:29
TomPeakz1-Dec-02 21:29 
GeneralRe: Excellent work! But ... Pin
Jim Koornneef24-Dec-02 3:30
Jim Koornneef24-Dec-02 3:30 

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

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