Forum Xamarin Xamarin.iOS

How to implement Bitmap library in Unified Xamarin Mac project

I just need Bitmap from System.Drawing. I'm using Xamarin.Mac . NET 4.5 Framework. And also I use QRCoder.dll and It needs Bitmap for returning image. How Can I use System.Drawing.Bitmap in my project? I downloaded sysdrawing-coregraphic. But I couldn't know how to use it. I couldn't find "mcs" path on OS X.

Best Answer


  • BehdadAhmadiBehdadAhmadi USMember

    Thank you so much. It has been compiled successfully. I added it in .NET assembly (in Edit References). And I wrote "using System.Drawing" . When I gonna use it, I face an error "The type System.Drawing.Bitmap' is defined in an assembly that is not referenced. Consider adding a reference to assemblySystem.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (CS0012) (usw)". It uses System.Drawing from default and built-in System.Drawing. How can I use my compiled System.Drawing.dll ?
    Thank you so much, You helped me a lot.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    If you re-read that error message, you might notice this part:


    That's the problem. The assembly you are apparently depending on itself already referenced a different System.Drawing:

    $ monop -r:/Library/Frameworks/Mono.framework/Versions/4.4.2/lib/mono/4.5/System.Drawing.dll

    Assembly Information:

    the one from mono 4.4.2. Even though both your System.Drawing version and that one have the same type, they don't match public keys, thus the error.

    If I had more closely read your original post, I would have realized that what you want won't work and told you that.

    You'd need to compile the library in question against that System.Drawing.dll version in order to use it.

    Everyone needs to agree on what assembly/type you are referencing.

  • BehdadAhmadiBehdadAhmadi USMember

    Thanks again. So I can't use the System.Drawing at all? How can I compile the library in question against System.Drawing?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    When you compile a library against a certain version of a dependency, it in general keeps track of that and requires that version to be loaded. That's how it knows to expect such and such class to have this methods and this property.

    The copy of System.Drawing shipped in mono is not an 100% exact match for the one you build from sysdrawing-coregraphics. In many ways it's rather close, but it isn't (nor meant to be) a drop in replacement.

    Your options are:

    • Recompile your library against the sysdrawing-coregraphics version (either do it yourself if you have source or go speak to your vendor).
    • Live with the fact that it depends on the system mono System.Drawing and all that entails.
  • BehdadAhmadiBehdadAhmadi USMember

    Aha. I change the library that I used to create QR code.
    I found another library to create QR code in BytesArray, How can bytes[] be converted to NSImage?
    Thank again.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    In many cases, such as this, googling for "Cocoa X" will provide a useful lead:

    I found a few answers under "cocoa nsimage from byte array"

Sign In or Register to comment.