I am trying to load high resolution image(like 3264x2448). For that I am using IImageFactory class in C#. IImageFactory is downloaded from the Microsoft site. If I try to load the high resolution image I am getting “out of memory” exception. Have a look at the below sample:
IImage GetIImage(string fileName)
{
Bitmap bitmap = null;
Graphics graphics = null;
IntPtr hdcDestination = IntPtr.Zero;
try {
IImage image = null;
IImagingFactory imagingFactory = ImagingFactory.GetImaging();
imagingFactory.CreateImageFromFile(fileName, out image);
bitmap = new Bitmap(width, height);
graphics = Graphics.FromImage(bitmap);
hdcDestination = graphics.GetHdc();
Rectangle dstRect = new Rectangle(0, 0, width, height);
image.Draw(_graphicsHDC, ref dstRect, IntPtr.Zero);
}
catch{}
}
Using the above source lines I was able to load the images but my effort to draw image fails, throwing an OutOfMemory Excep :( Further, I tried the same by creating a Win32 mobile App, in which I could bot Load and Draw the desired images with the following lines.
void DrawImage(HDC *hdc, char *FileName, int width, int height)
{
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL;
RECT rc = { 0, 0, width, height};
WCHAR Name[MAX_PATH] ={0};
mbstowcs (Name, FileName, strlen (FileName));
CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&pImgFactory)))
{
// Load the image from the JPG file.
if (SUCCEEDED(pImgFactory->CreateImageFromFile(Name, &pImage)))
{
pImage->Draw(*hdc, &rc, NULL);
pImage->Release();
}
pImgFactory->Release();
}
CoUninitialize();}
I even tried creating a win32 dll and invoke it from C# app but I couldn't. Can anyone help me out to resolve this issue?