我試圖加載高分辨率圖像(如3264x2448)。爲此,我在C#中使用IImageFactory類。 IImageFactory從Microsoft網站下載。如果我嘗試加載高分辨率圖像,則會出現「內存不足」異常。看看下面的例子:使用IImagingFactory加載高分辨率圖像時出現內存不足異常
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{}
}
使用上面的源代碼行我能加載圖像,但我的努力來繪製圖像失敗,拋出內存溢出Excep :( 此外,我想同樣的創建一個Win32移動應用程序,其中我能BOT荷載及以下線路繪製所需的圖像。
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();}
我甚至嘗試創建一個Win32 DLL和C#應用程序調用它,但我不能。 任何人都可以幫我解決這個問題嗎?
你還問這個問題已經:http://stackoverflow.com/questions/1490652/how-to-load-the-high-resolution-images-in-windows-mobile/1491591#1491591 如果AREN '不滿意縮略圖給你的調整大小的結果,然後你需要自己調整圖像的大小 – Matt 2009-10-05 23:01:42
雅..馬特..我堅持任何方式我想嘗試一些:-( – Naruto 2009-10-06 05:00:12