Having trouble getting Windows CE/Windows Mobile factory working to load pictures?
The code below will load a JPG/GIF/PNG (or whatever decoders are installed on your device) etc from a file and paint it to the screen:
CoInitializeEx(NULL, 0);
IImagingFactory* pImageFactory;
IImage *pImage = NULL;
HDC dc = GetDC(0); // insert your window handle here, else this is the desktop
HRESULT hr = CoCreateInstance(CLSID_ImagingFactory, NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IImagingFactory),
(LPVOID *)&pImageFactory);
// Load image from file
pImageFactory->CreateImageFromFile(bitmapName, &pImage);
// Get image information
ImageInfo info;
pImage->GetImageInfo(&info);
RECT rc={0,0,info.Width, info.Height};
// draw jpg/gif etc onto temp dc
pImage->Draw(dc, &rc, NULL);
// Clean up
pImage->Release();
pImageFactory->Release();
CoUninitialize();
Thursday, 14 June 2007
Subscribe to:
Post Comments (Atom)
9 comments:
Hi,
I tried including this in Pocket PC2003 but get the following error.
: fatal error C1083: Cannot open include file: 'GdiplusPixelFormats.h': No such file or directory
Can you tell me where should I place the file "bitmapName" (CreateImageFromFile). In which folder. I am getting error file not found. I have tried placing it in the folder where I my worksapce is but nothing seems t work.
Hi,
I tried including this in Pocket PC2003 but get the same error as above.
: fatal error C1083: Cannot open include file: 'GdiplusPixelFormats.h': No such file or directory
Windows CE / Pocket PC has no concept of current working directories, so you must specify the whole path, i.e.
From an external disk like
\sd card\mybitmap.bmp
or from the root mounted file system (this maybe ram or flash depending on the OS setup)
\mybitmap.bmp
For the includes you should be using (in addition to your afx.h / windows.h and others):
#include "INITGUID.h"
#include "imaging.h"
Could you give me a hand on how this could be done in VB.NET or at least the libraries and/or DLLs I should check out. I would really appreaciate it!
Cheers,
Mike
Sorry not really sure in VB, isn't there built in handling in VB to support loading and saving of png/jpg etc files using the
System.Drawing.Imaging
or
Dim g As Graphics = Graphics.FromImage(bmp)
Type commands (just from a google), these will invariably be just calling the imaging factory underneath anyhow, or do you want lower access than VB allows?
Cheers
Graeme
Hi I need a method to acces the image pixel (i,j) with imaginfactory before draw it in the hdc to transfer the pixel to an array.
Actually i drawn it and acces the pixel in the hdc with GetPixel but this method is very slow.
You should use CreateDIBSection to create a device independent bitmap, this returns a pointer to the memory buffer that makes up the bitmap, draw to this DC then access the array of pixels directly, much much quicker than get pixel but you will have to work out the bit ordering for the RGB pixels.
Post a Comment