Displaying JPG Images with .NET CF impossible?

X

xalex

Hi,
we are developing an application that lets you annotate your Images on
the compact flash card of your
digital camera to store the images wirh annotations later in an image
database.
i want to show large JPGs (or only the thumbsnails containing in the
larger imagges) with the code below:

Bitmap bm = new Bitmap(filename);
imageBox.Image = bm;

Small jpg are shown perfectly, larger files (3megapixel or more) cause
the system.drawing.dll throw
an exception (unknonw exception with the helpful message 'Exception' )

I browsed the web and found the infos below about imgdecmp.dll and the
undocumented APIs
SHLoadImageFile and SHLoadImageResource

It cant be true, that it isnt possible to display images with Compact
Framework (1.1)
Is there an open or cloed source library that supports displaying jpgs?

Thanks,
Alex

--
Alexander Ramisch mailto:[email protected]
pixafe GbR http://www.pixafe.com


Infos about the undocumented API:
Windows Mobile devices have traditionally included a ROM library called
imgdecmp.dll for Microsoft applications to use. This library exported
an API that was not documented in the SDK, but it has been used by
developers to load image files. Starting with Windows Mobile 2003
Second Edition, SHLoadImageFile and SHLoadImageResource were added
into the headers for aygshell.h. These APIs should be used in place of
imaging support previously provided by imgdecmp.dll. Alternatively,
advanced imaging APIs are provided by imaging.h for applications
targeting Windows Mobile 5.0 or later. On Windows Mobile 5.0,
applications may get caught in an infinite loop if they call the
DecompressImageIndirect function with a DecompressImageInfo structure
with a prepopulated buffer and without specifying a correct non-zero
value for dwBufferCurrent. Note Imgdecmp.dll will be removed from a
future version of the Windows Mobile platform.
 
P

Peter Kellner

I'm not sure why you call SHLoadImageFile an undocumented API - what about
http://msdn.microsoft.com/library/en-us/apippc/html/ppc__mdref_shloadimagefile.asp ?
A 3 megapixel JPEG indeed may have problems being opened using Bitmap class,
since the uncompressed bitmap is over 6 MB
As for 3rd party JPEG library, perhaps this can be of some help (I haven't
tried it) http://www.pocketpcdn.com/articles/jpeglib.html

I' really appreciate it if you would post a small piece of code showing
an example of using SHLoadImageFile to create a viewable image (ie,
small image)

Thanks
 
A

Alex Feinman [MVP]

SHLoadImageFile is not capable of creating a preview bitmap if that's what
you mean. It will attempt to load the whole image, sufferring from the same
limitaitons as Bitmap constructor. The Bitmap constructor internally call
SHLoadImageFile (SP2 and newer. RTM and SP1 used DecompressImageIndirect)
 
P

Peter Kellner

This followup was posted to
microsoft.public.dotnet.framework.compactframework

SHLoadImageFile is not capable of creating a preview bitmap if that's what
you mean. It will attempt to load the whole image, sufferring from the same
limitaitons as Bitmap constructor. The Bitmap constructor internally call
SHLoadImageFile (SP2 and newer. RTM and SP1 used DecompressImageIndirect)


I' really appreciate it if you would post a small piece of code showing
an example of using SHLoadImageFile to create a viewable image (ie,
small image)

I'm still very interested if there is a example out there using C#
(possibly using DecompressImageIndirect) that will let me retrieve a
large image (3MB's or so) and create a preview bitmap.

Thanks
 
A

Alex Feinman [MVP]

Sorry, this kind of things cannot be done entirely in .NET. Even in CF 2.0
someone will have to write interop code. Here is a starting point if you
decide to have a go at it:

extern "C" int LoadThumbnail(LPCTSTR szImage, int cx, int cy)

{

CoInitializeEx(NULL, COINIT_MULTITHREADED);

{

CComPtr<IImagingFactory>pFactory;

CComPtr<IImage>pImg;

CComPtr<IImage>pThumbImage;

pFactory.CoCreateInstance(CLSID_ImagingFactory);

HRESULT hr = pFactory->CreateImageFromFile(szImage, &pImg);

if ( FAILED ( hr ) )

return hr;

hr = pImg->GetThumbnail(cx, cy, &pThumbImage);

if ( FAILED ( hr ) )

return hr;

CComPtr<IBitmapImage>pBitmap;

hr = pFactory->CreateBitmapFromImage(pThumbImage, cx, cy,
PIXFMT_16BPP_RGB565, InterpolationHintDefault, &pBitmap);

if ( FAILED ( hr ) )

return hr;

RECT rc = { 0, 0, cx, cy };

BitmapData data;

hr = pBitmap->LockBits(&rc, ImageLockModeRead, PixelFormat16bppRGB565,
&data);

// Add here code that creates BITMAPFILEHEADER and the rest of data
structures and generates a byte array suitable for using with Bitmap
constructor

}

CoUninitialize();

return 0;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top