- Home /
Trying to use FreeImage won't work in Editor
I'm using Unity Free for a project (which is going to end up more of a personal tool for a public thing) and I'm trying to get GIFs loaded off the Internet to animate.
I'd tried using a semi-hybridization of the AnimatedGifDrawer and a small snippit I'd found to load images off the Internet and read it directly from memory. It went something like this:
WWW www = new WWW("http://mspaforums.com/image.php?u=" + id);
while(!www.isDone) { }
MemoryStream stream = new MemoryStream(www.bytes);
var img = Image.FromStream(stream);
...and proceeded from there like the AnimatedGifDrawer recipe. My only problem was that it didn't seem to like that - it threw UnsupportedOperationException
's when trying to img.SelectActiveFrame(dim,i)
(`dim` is dimension
from the recipe) so I instead decided to try using FreeImage. After all, Unity itself uses FreeImage, so it shouldn't be too hard to use it myself, right?
I'd changed the code around a little bit. Instead of using Image.FromStream
I used FreeImageBitmap.FromStream
and changed the code from the recipe to fit FreeImage's stuff. I've also stuck FreeImage's IsAvailable
near the top to make sure it's loaded before trying to use it:
if(!FreeImage.IsAvailable()) {
Debug.LogError("FreeImage not available?!?!", this);
return;
}
Weird thing is, `IsAvailable` returns false
(throwing my error) when it runs in the Editor, but when I try to run it from a built Standalone it returns true
. It's already in the executable's folder (since Unity's using it itself), I've tried putting FreeImage.dll in System32 (probably not a smart idea, honestly) as well as making a folder called ExtraPATH, adding that to the PATH variables (probably double-not-smart), and sticking the DLL in that, no dice. Is there something I'm missing to let Unity use FreeImage within the Editor?
Answer by The Stick · May 05, 2014 at 04:55 PM
Oh. That's just great.
In order to use a DLL that's supposed to be in the same directory as the Executable (ie FreeImage.dll) you need to stick it in a Plugins folder on the root of your Assets folder.
The only issue is, in order to use the plugin (either just FreeImage or any DLL), you need to use Unity Pro:
License Error. This plugin is only supported in Unity Pro!
FreeImageAPI.FreeImage:IsAvailable()
FreeImageAPI.FreeImage:IsAvailable()
Avatar:constructor(Int32)
...
Lovely. Just lovely.
Your answer
