简体   繁体   中英

FreeImage on C#

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM