Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Using Bitmaps in Unity

Discussion in 'Scripting' started by NitzscheT, May 27, 2020.

  1. NitzscheT

    NitzscheT

    Joined:
    Apr 22, 2020
    Posts:
    17
    I am currently using the Accord.NET framework and I've come across the problem that I need to somehow use Bitmaps. I have
    using.System.Drawing;
    but apparently that isn't really compatible with unity. Is there some way to work around this? I've read some posts about using different .dlls to achieve this, anyone know something about that? Any advice is appreciated. Thanks!
     
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    247
    Last edited: May 27, 2020
  3. NitzscheT

    NitzscheT

    Joined:
    Apr 22, 2020
    Posts:
    17
    Hi again @arfish, I saw the first post as well. So its probably better to just try and rewrite the Accord.NET library to take a different class type? Sounds like a hell of a job. Ill give it a go. The second link might be useful, Ill have to try..
     
  4. NitzscheT

    NitzscheT

    Joined:
    Apr 22, 2020
    Posts:
    17
    Okay so after a lot of research I am still not sure how to solve this. It seems that one can import the System.Drawing.dll but when I do it, Unity just tells me that the .dll is already in the project and thus i should delete on of them.
    I am unable to find a library that implements Bitmaps, only ones that implement an equivalent (e.g. SkiaSharp), but those arent compatible with the Accord.NET framework Im using. So I am a bit at a loss. Where am I even supposed to get the System.Drawing.dll from? Is there an official place? I dont want to download one from some shady dll library. I looked on a chinese website and it said that I can just copy the same one that is already in Unity, but that seems to make no sense, as the dll Unity uses doesnt contain Bitmaps (or atleast doesnt give me access to them), so I would just be duplicating a useless dll. Can I simply download the full System.Drawing.dll and then replace the one already in unity? Any help is welcome!
     
  5. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    247
    If you just need compact storing of large amounts of ones, and zeros.
    Perhaps it's easier to just write an own class to use an array of ints, as a 2d array of bits?
     
  6. NitzscheT

    NitzscheT

    Joined:
    Apr 22, 2020
    Posts:
    17
    Not exactly, I am using the Accord.Net framework to have access to their Image Stitching functions. The things is that they have not built it for unity specifically but as a c# console application and they thus have access to all the .NET libraries and can use Bitmaps. For some reason Unity doesnt use all the .NET libraries and that sadly includes half of System.Drawing. Which includes Bitmaps. Im not smart enough to go through the whole Accord.Net code and change their image stitching to rely on something other than Bitmaps, so I thought I could find a way to either implement System.Drawing.Bitmaps into Unity, or to find a plugin that implements it (I actually think this isnt really possible). I havent been able to achieve either.
     
  7. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,445
    It is possible quite easily without even manually adding any dll. It does limit your build to Windows only and it requires .NET 4.x to be selected in the build setting.

    To add/import System.Drawing, just add a file named csc.rsp in Assets with the contents:
    Code (csharp):
    1.  
    2. -r:System.Drawing.dll
    3.  
    Restart Unity after importing to take effect.
     
  8. NitzscheT

    NitzscheT

    Joined:
    Apr 22, 2020
    Posts:
    17
    Lol. @jvo3dc thank you so much. That works. Gonna have to figure out now how to find a solution for android, but that is an immense help. Thanks a lot. Seriously.
     
unityunity