Magick.net: Xamarin Support

Created on 4 Nov 2016  路  18Comments  路  Source: dlemstra/Magick.NET

Hello,
I would like to include support for Xamarin,
but I need a bit of guidance.

enhancement help wanted

Most helpful comment

Hello,

what is the actual status? I use ImageMagick with success in a Xamarin project when running as UWP. When using on the IPhone I fail.
I take a photo with the internal camera, which is working fine and try then to create a MagickImage within a .NET Standard 2.0 project:
ImageMagick.MagickImage image = new ImageMagick.MagickImage(new FileInfo(photo.Path));
This leads to
The type initializer for 'NativeMagickSettings' threw an exception.
I tried Magick.NET-Q8-AnyCPU (7.4.3) and Magick.NET-Q16-AnyCPU (7.4.3) with no success.
Any idea how to solve this or is there still no full implementation for Xamarin?

All 18 comments

It would be really cool if you could add Xamarin support. To make this possible you will need to create a build script that creates lib files that can be used on IPhone/Android. You can take a look what happens under Windows here: https://github.com/dlemstra/Magick.NET/blob/master/Building.md. Instead of BuildAll.cmd there should be a shell script that statically builds the binaries for IPhone/Anroid.

Hi Dirk,
thanks. I will look at that and revert to you.
be ready to get bugged a lot for assistance.

Hello Dirk,
i am having issues building the libraries,
could you help ?

My primary expertise is Windows and not Unix/Linux. But I think the goal should be building each library step by step. Do you have a script of what you have done so far?

well still trying to build the script for the main version on Windows.
for Xamarin it should be the same process but I want to target see if I can do it with a PCL.

Hello, I am still encountering the following error : LNK1104, unable to find file "bzib.lib"
I checked the files and it is there.

please keep this open. I will work on this when I got some free time.

Hello, I have not forgotten about this. Migrating this library will be easier now with .net standard 2.0 and the new windows compatibility pack announced yesterday at dotnet conf. 2017.

Still have some timing issues to work on this.

Hello,

what is the actual status? I use ImageMagick with success in a Xamarin project when running as UWP. When using on the IPhone I fail.
I take a photo with the internal camera, which is working fine and try then to create a MagickImage within a .NET Standard 2.0 project:
ImageMagick.MagickImage image = new ImageMagick.MagickImage(new FileInfo(photo.Path));
This leads to
The type initializer for 'NativeMagickSettings' threw an exception.
I tried Magick.NET-Q8-AnyCPU (7.4.3) and Magick.NET-Q16-AnyCPU (7.4.3) with no success.
Any idea how to solve this or is there still no full implementation for Xamarin?

busy with other priorities, if you can take this on, then go ahead

The issue @MPusch described is still unsolved. With the current version of Magick.NET (7.5.0.1) I get the exact error.
But when you look at the internal exception "Failed to load dll Magick.NET-Q8-AnyCPU.dll". But I have absolutely no idea why this happens.

Shouldn't the core C++ library made compatible with .net standards ? Is there an easy way to do that ?

Not sure what you are asking? The native C library of Magick.NET (called Magick.Native) works on the Windows, Linux and MacOS.

I was able to run Magick.NET on the Xamarin.Mac runtime on the Mac OS X with the following steps:

  1. Create a Xamarin.Mac Cocoa project (targeting Xamarin.Mac Modern or Xamarin.Mac Full 4.8)
  2. Add Magick.NET-Q8-x64 Nuget package and some Magick.NET-related test code.
  3. Build and try to run - you will get the error described above (The type initializer for 'NativeMagickSettings' threw an exception.)
  4. Open output folder of the project, then open the bundle (in Finder, right click and select Show package contents) and go to the Contents/MonoBundle folder (so, the full path will be /bin/Debug/.app/Contents/MonoBundle
  5. Copy file /packages/Magick.NET-Q8-x64.7.15.4/runtimes/osx-x64/native/Magick.Native-Q8-x64.dll.dylib to the to the MonoBundle folder, then rename the copy to the Magick.Native-Q8-x64.dll (drop .dylib)
  6. Run the bundle - it should work fine.
  7. After full rebuild you will need to copy file again. But after partial rebuild all still works fine.

So, the conclusion is:

  • Looks like both managed and native parts of Magick.NET work fine with xamarin.mac environment.
  • The problem is somewhere in build system or in nuget platform selection.

Note: this solution will not work on Iphone/android because of lack of the native ImageMagick libraries built for these platforms. This is also will not work with AnyCPU builds, because this builds will extract (wrong) native library at runtime.

Closing this for now.

Hi, the code works brilliant on Xamarin.UWP, but on Xamarin.Android (and probably iOS as well) it fails with communicate
System.DllNotFoundException Magick.Native-Q8-x64.dll assembly: type: member:(null).

Could anyone help to create the mentioned build scripts or Xamarin.iOS and Xmarin.Androind ?

@snechaev , you wrote that:
_"Note: this solution will not work on Iphone/android because of lack of the native ImageMagick libraries built for these platforms."_
As of now on the homepage of the ImageMagick project they state that there is official support for iOS and Android.
_"(The current release is ImageMagick 7.0.11-12. It runs on Linux, Windows, Mac Os X, iOS, Android OS, and others.)"_
Do you think that the workaround you did with Mac could also work for iOS and Android ?

@MichalJan008, I don't know much about imagemagick internals and I did not tryed this for ios/android. But I can assume that if you will get platform-specific IM binaries (.so for android and .dylib for iOS), the approach described above may work. But you still can get issues with emulators, as iOS emulator is actually x86 (and you will pack arm-targeted dylib).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zygimantaskazlauskas picture zygimantaskazlauskas  路  3Comments

zhangnan0324 picture zhangnan0324  路  8Comments

itty53 picture itty53  路  4Comments

tttrrryyyyeer picture tttrrryyyyeer  路  6Comments

tttrrryyyyeer picture tttrrryyyyeer  路  6Comments