Questions tagged [system.drawing]

System.Drawing is a namespace of the .NET framework. It provides access to GDI+ basic graphics functionality.

System.Drawing is a namespace of the .NET framework. It provides access to GDI+ basic graphics functionality.

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. For a supported alternative, see Windows Imaging Components.

References

1129 questions
208
votes
3 answers

Why is DarkGray lighter than Gray?

Simple curiosity here, tinged with some practical concerns because I get caught out by this occasionally. How come Color.DarkGray is lighter than Color.Gray? This behaviour is also shown in CSS where the property color: darkgrey renders #A9A9A9 and…
Benjol
  • 63,995
  • 54
  • 186
  • 268
104
votes
14 answers

c# Image resizing to different size while preserving aspect ratio

I'm trying to resize an image while preserving the aspect ratio from the original image so the new image doesn't look squashed. eg: Convert a 150*100 image into a 150*150 image. The extra 50 pixels of the height need to be padded with a white…
sf.
  • 24,512
  • 13
  • 53
  • 58
86
votes
18 answers

A Generic error occurred in GDI+ in Bitmap.Save method

I am working on to upload and save a thumbnail copy of that image in a thumbnail folder. I am using following link: http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx but newBMP.Save(directory +…
donstack
  • 2,557
  • 3
  • 29
  • 44
82
votes
4 answers

Manipulating images with .NET Core

I have updated my project from .NET 4.5 to .NET Core (with ASP.NET Core). I had some very simple code in my previous version that used the bitmap object from System.Drawing to resize an image. As I understand System.Drawing cannot be used in .NET…
Gillardo
  • 9,518
  • 18
  • 73
  • 141
49
votes
5 answers

how can I convert System.Drawing.Icon to System.Drawing.Image?

I'm getting icon from another application using this: Icon IEIcon = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe"); how to convert it to System.Drawing.Image?
The Mask
  • 17,007
  • 37
  • 111
  • 185
46
votes
11 answers

How to find reason for Generic GDI+ error when saving an image?

Having a code that works for ages when loading and storing images, I discovered that I have one single image that breaks this code: const string i1Path = @"c:\my\i1.jpg"; const string i2Path = @"c:\my\i2.jpg"; var i =…
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
37
votes
2 answers

System.Drawing.Brush from System.Drawing.Color

I'm developing a WinForm Printing application for our company. When the document is printed, I need to take the System.Drawing.Color property of each Control on the document and create a System.Drawing.Brush object to draw it. Is there a way to…
user153923
35
votes
8 answers

Alternatives to System.Drawing for use with ASP.NET?

After several days of tracking down bizarre GDI+ errors, I've stumbled across this little gem on MSDN: Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from…
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
34
votes
4 answers

Bad text rendering using DrawString on top of transparent pixels

When rendering text into a bitmap, I find that text looks very bad when rendered on top of an area with non-opaque alpha. The problem is progressively worse as the underlying pixels become more transparent. If I had to guess I'd say that when…
mackenir
  • 10,801
  • 16
  • 68
  • 100
34
votes
1 answer

How to take a screenshot of a WPF control?

I created a WPF application using the Bing maps WPF control. I would like to be able to screenshot only the Bing maps control. I use this code to make the screenshot: // Store the size of the map control int Width = (int)MyMap.RenderSize.Width; int…
Walter Fabio Simoni
  • 5,671
  • 15
  • 55
  • 80
33
votes
2 answers

Convert System.Drawing.Color to System.Windows.Media.Color

System.Drawing.Color drawRedColor = System.Drawing.Color.Red; System.Windows.Media.Color mediaColor = ?drawRedColor.ToMediaColor();?
serhio
  • 28,010
  • 62
  • 221
  • 374
25
votes
2 answers

Cannot find Bitmap Class in Class Library (.NET Standard)

I want to make a Class Library (.NET Standard) and I'm using System.Drawing, but I get the error: CS0246 C# The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?) I'm using .NET…
IIRawCodeII
  • 375
  • 1
  • 3
  • 9
24
votes
7 answers

Selecting the size of a System.Drawing.Icon?

I have a icon which has a few different sizes (16px, 32px, 64px). I am calling ToBitmap() on it, but it is always returning the 32px image. How do I retrieve the 64px one?
Andy Hin
  • 30,345
  • 42
  • 99
  • 142
24
votes
3 answers

What is the difference between System.Drawing.Point and System.Drawing.PointF

What is the difference between System.Drawing.Point and System.Drawing.PointF. Can you give an example between this two. Thanks in advance.
Rye
  • 2,273
  • 9
  • 34
  • 43
23
votes
2 answers

.NET Image.Save occasionally generates a PNG with a bad IDAT chunk

I have a C#/.NET utility I wrote that loads PNG images from disk Bitmap b = Bitmap.FromStream(new MemoryStream(File.ReadAllBytes(filename))) as Bitmap; performs several transformations on them (rotation, scaling, alpha) and then saves the resulting…
David Welch
  • 369
  • 1
  • 9
1
2 3
75 76