3

I am new to C# and I am trying to create a bitmap object in C# in Visual Studio 2019, but it isn't working. I have .NET Framework updated to the latest version and I have resharper installed. I am using Windows 10.

Ive tried adding the references manually with Add/Reference... and it does not stay checked.
I added using system.drawing and using system.drawing.common to the top of my code.
I updated my .net core and enabled it in my project.

using System; using System.Drawing.Common; namespace Bot { class Program { static void Main(string[] args) { var bmp = new Bitmap(); } } } 

I expected it to create a bitmap object, but it won't compile and gives me errors saying that the bitmap object does not exist in system.drawing.

5
  • 1
    You need to add reference to System.Drawing.dll, read the instructions here. Commented May 4, 2019 at 17:30
  • Have you installed the System.Drawing.Common NuGet package? When you have, add using System.Drawing;, then write var bmp = new Bitmap(1, 1); (you need to specify a size or a source Image or a file path or a stream). Commented May 4, 2019 at 17:40
  • How do I install that? Sorry, I just started learning C# and VS a month ago Commented May 4, 2019 at 17:50
  • Tools -> NuGet Package Manager - Manage NuGet Packages for Solution. Search System.Drawing.Common and install it, ticking all the checkboxes (Project) you find in the panel on the right. Commented May 4, 2019 at 18:21
  • 1
    What are you targetting: Winforms, WPF, ASP..? YOU should always TAG your questions correctly so one can see it on the questions page! In your case do Tag .NET Core! Commented May 4, 2019 at 19:23

2 Answers 2

4

The Bitmap class if part of the assembly System.Drawing.Common.dll, so you need to install System.Drawing.Common via the Nuget Package.

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you don't have the package in your system/project. In you're project directory or from VScode terminal do this:

dotnet add package System.Drawing.Common --version 6.0.0 

then add a reference to the package in you're project

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.