PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Save / Load Image Problem

Hi, all.

I have an application which calls SaveImage to save a screen shot as a bitmap. The image is successfully saved, and is about 150K in size. I can copy it to desktop, and view it fine in Paintshop Pro.

The problem occurs when I call LoadImage. For some reason, the DecompressImageIndirect call in src\image.cpp is failing on both my Casio E-100 & E-200 devices. Calling FormatMessage(..,GetLastError(), .. ) returns the string "Cannot create file when that file already exists".

Any help is appreciated. I have a sample screen shot program which illustrates the problem. Here is the link: [url]mccawclan.home.attbi.com/screenshot.cpp[/url]. I would be curious to know if it happens on other devices as well.

Thanks,
Ken
Hi George, I did receive your email about this problem but didn't have time to look into it.

It might be that the BMP format used by PocketFrog to save the image is not compatible with imgdecmp.dll... Although it seems that the error message is saying otherwise... Could you post the code you use to save / load the image?
Sure - here is the snippet from the screen shot sample:
Code:


/*************************************************************************
* function: LoadScreenShot
* purpose : Load an image generated by the SaveImage function.
* params : lpFileName - name of screenshot file on device.
* returns : none.
*************************************************************************/
void LoadScreenShot( LPCTSTR lpFileName )
{
DisplayDevice* dd = GetDisplay();
Surface* image = LoadImage( dd, lpFileName );

if ( image ) {
dd->SetRenderTarget( m_screenshot );
dd->Blit( 0, 0, image );
delete image;

// ...
} else {
LPTSTR lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf;,
0,
NULL );
MessageBox( NULL, lpMsgBuf, _T("INFO"), MB_OK );
OutputDebugString( lpMsgBuf );
free( lpMsgBuf );
}
}

/*************************************************************************
* function: SaveScreenShot
* purpose : Save contents of surface to bitmap file.
* params : lpFileName - name of screenshot file on device.
* returns : none.
*************************************************************************/
void SaveScreenShot( LPCTSTR lpFileName )
{
LPTSTR lptr = _tcsstr( lpFileName, _T(".bmp"));

if ( lptr ) *lptr = 0; // SaveImage appends .bmp...

SaveImage( m_screenshot, lpFileName );

// ...

}


In this snippet, m_screenshot is a surface created in GameInit() using the CreateSurface( 240, 320 ). If you want to see what the other functions & member vars are, refer to the link in my initial post. The SaveImage call will work, and the lpFileName file is created. When you call LoadImage on the same file, the image is NULL and the "file already exists" message box is displayed.

I tried playing with the DecompressImageIndirect parameters in src/image.cpp, to no avail. The cryptic error message string does not really help solve the problem, either. Worse case, I can substitute a custom LoadImage routine - but I hate to reinvent the wheel if it is not needed!

Thanks,
Ken
Ken_McCaw · 24 Jul 2002, 03:49 UTC — Found a fix...
I found an article on usenet ( dated 1999! ) that claims the video driver on the Casio 10x series does not support CreateDIBSection on a 16-bit DIB. I can now verify the problem on the E-200 as well!

Fortunately, I found that by replacing the call into imgdecmp.dll with a SHLoadDIBitmap works great:

Code:

#if ( _WIN32_WCE>=300 )
#include <shellapi.h>
#elif ( _WIN32_WCE>=211 )
#include <commctrl.h>
#elif
#error SHLoadDIBitmap not supported
#endif

//
// function: LoadBitmapToSurface
// purpose : Use this to load 16 bpp bitmaps on casio
//
Surface* LoadBitmapToSurface( DisplayDevice* display, const TCHAR* filename )
{
HBITMAP hbmp = SHLoadDIBitmap( filename );
Surface* image = NULL;
if ( hbmp ) {
image = CreateSurface( display, hbmp );
::DeleteObject( hbmp );
}
return image;
}


The CreateSurface function can be found in the src/image.cpp module of the PocketFrog library. It may be easiest to just remove the "static" from it and prototype it in the module which requires this fix.

I need to confirm this works on my E-100, but it works great on the PocketPC 2002 device.

HTH any Casio owners out there!

Ken