FreeImage on C#

核能气质少年 提交于 2019-12-25 05:14:02

问题


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;
            }*/

        }

It always throws BadImageFormatException. It seems the problem is on the native dll (freeimage.dll) ?

How do I fix it ?

Thanks in advance.

I'm using Visual C# 2010 Express


回答1:


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.



来源:https://stackoverflow.com/questions/11432041/freeimage-on-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!