FreeImage在C# [英] FreeImage on C#
问题描述
我已经下载了FreeImage的最新编译版本,然后构建FreeImageNet包装器。将FreeImage.dll和FreeImageNet.dll放在与我的可执行文件(示例代码)相同的文件夹上。但是每次运行它,都表示freeimage.dll丢失。我修改了FreeImageWrapper.cs上的代码,并删除了异常处理程序。
I've downloaded the latest compiled version of FreeImage, then build FreeImageNet wrapper. Put FreeImage.dll and FreeImageNet.dll on the same folder as my executable (the sample code). But everytime I run it, it says freeimage.dll is missing. I modified the code on FreeImageWrapper.cs and remove the exception handler
public static bool IsAvailable()
{
/*try
{*/
// Call a static fast executing function
Version nativeVersion = new Version(GetVersion());
Version wrapperVersion = GetWrapperVersion();
// No exception thrown, the library seems to be present
return
(nativeVersion.Major > wrapperVersion.Major) ||
((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor > wrapperVersion.Minor)) ||
((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor == wrapperVersion.Minor) && (nativeVersion.Build >= wrapperVersion.Build));
}
/*catch (DllNotFoundException)
{
return false;
}
catch (EntryPointNotFoundException)
{
return false;
}
catch (BadImageFormatException)
{
return false;
}*/
}
它总是抛出BadImageFormatException。似乎问题是在native dll(freeimage.dll)?
It always throws BadImageFormatException. It seems the problem is on the native dll (freeimage.dll) ?
如何解决?
提前感谢
我使用Visual C#2010 Express
I'm using Visual C# 2010 Express
推荐答案
如果您尝试将非托管32位dll加载到64位进程中,则会发生这种情况。要解决这个问题,请打开启动项目的属性,然后在Built-PlatformTarget下将类型从任何CPU
更改为 x86
。
This happens very often if you try to load a unmanaged 32bit dll into a 64bit process. To get around this problem open the properties of your startup project and change under Built - PlatformTarget the type from Any CPU
to x86
.
这篇关于FreeImage在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!