【发布时间】:2010-12-04 00:10:47
【问题描述】:
我正在尝试加载高分辨率图像(如 3264x2448)。为此,我在 C# 中使用 IImageFactory 类。 IImageFactory 是从 Microsoft 站点下载的。如果我尝试加载高分辨率图像,则会出现“内存不足”异常。看看下面的示例:
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{}
}
使用上面的源代码行,我能够加载图像,但我绘制图像的努力失败了,抛出了 OutOfMemory Excep :( 此外,我通过创建一个 Win32 移动应用程序进行了同样的尝试,在该应用程序中我可以使用以下几行代码加载和绘制所需的图像。
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# 应用程序调用它,但我做不到。 谁能帮我解决这个问题?
【问题讨论】:
-
你也已经问过这个问题了:stackoverflow.com/questions/1490652/…如果你对缩略图给你的调整结果不满意,那么你需要自己调整图像大小
-
ya.. matt.. 我被卡住了,我正在尝试一些方法:-(
标签: c# windows-mobile mfc winapi compact-framework