Search Unity

The type or namespace name 'Bitmap' could not be found

Discussion in '2D' started by TheWebExpert, Feb 15, 2020.

  1. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    I'm usuing Unity version 2019.3.1f1. Here's my code (thus far)...

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Drawing;
    5. using UnityEngine;
    6.  
    7. public class RemoveBackground : MonoBehaviour
    8.   {
    9.     void BlankImage()
    10.       {
    11.         Bitmap myBitmap = new Bitmap("Grapes.jpg");      
    12.       }
    13.   }
    14.  
    However, 'Bitmap' isn't recognized. I've seen several articles on the web from older versions of Unity, suggesting that the System.Drawing.dll file needs to be in the Library folder for the project. However, this didn't change anything. I can't go any further with this project until this error is resolved. Anyone got any answers?
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    usually need to place the dll in the project root folder,
    also try adjusting api compatibility level in build settings (if standard is selected, select the other one).
     
  3. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    I have the DLL in both the project root AND in the Library folder; the API compatibility level is either .NET Standard 2.0 or else .NET 4.x -- neither choice makes any difference.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    do you have windows platform selected?
     
  5. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    It's PC, Mac etc. standalone, with Windows selected.
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    can you zip the project where it doesn't work, ill test? (you can test it in empty project, no need to include your own files)
     
  7. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    The only thing in this file is the assets; you'll have to create a new project to put it into - the whole file was too large to upload.
     

    Attached Files:

    • Test.zip
      File size:
      18.7 KB
      Views:
      449
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    ok, so it seems to work if place the System.Drawing.dll in Plugins/ folder
    (and set API compatibility .NET 4.x)

    there's multiple of those System.Drawing.dll files, i took mine from C:\Windows\Microsoft.NET\Framework64\v4.0.30319
     
    radiantboy, AB498, ubedjunejo and 2 others like this.
  9. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    Awesome. That did it. Apparently, all the directions out there were telling me to put the file in the wrong place. I had the right file, but the wrong location... putting it into the plugins folder did the trick. My program now clears the white background out of a picture - which is PRECISELY what I needed it to do! Thanks!
     
  10. ismaelnascimentoash

    ismaelnascimentoash

    Joined:
    Apr 2, 2017
    Posts:
    30
    Its works for me ! Thanks
     
  11. kalechips_

    kalechips_

    Joined:
    Dec 21, 2019
    Posts:
    5

    This worked! I had to do both: move System.Drawing.dll into Assets/Plugins and set API to .NET 4.x