Questions tagged [gdi+]

The Graphics Device Interface (GDI) is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. -Wikipedia

Questions about the GDI+ drawing library/API, including the Gdiplus namespace in C++ and the System.Drawing namespace in .NET languages.

2771 questions
341
votes
34 answers

A generic error occurred in GDI+, JPEG Image to MemoryStream

This seems to be a bit of an infamous error all over the web. So much so that I have been unable to find an answer to my problem as my scenario doesn't fit. An exception gets thrown when I save the image to the stream. Weirdly this works perfectly…
madcapnmckay
  • 15,293
  • 6
  • 58
  • 77
128
votes
3 answers

Resize image proportionally with MaxHeight and MaxWidth constraints

Using System.Drawing.Image. If an image width or height exceed the maximum, it need to be resized proportionally . After resized it need to make sure that neither width or height still exceed the limit. The Width and Height will be resized until it…
Sarawut Positwinyu
  • 4,544
  • 13
  • 47
  • 71
116
votes
17 answers

Image.Save(..) throws a GDI+ exception because the memory stream is closed

i've got some binary data which i want to save as an image. When i try to save the image, it throws an exception if the memory stream used to create the image, was closed before the save. The reason i do this is because i'm dynamically creating…
Pure.Krome
  • 78,923
  • 102
  • 356
  • 586
94
votes
8 answers

Draw a single pixel on Windows Forms

I'm stuck trying to turn on a single pixel on a Windows Form. graphics.DrawLine(Pens.Black, 50, 50, 51, 50); // draws two pixels graphics.DrawLine(Pens.Black, 50, 50, 50, 50); // draws no pixels The API really should have a method to set the color…
Mark T
  • 3,292
  • 3
  • 29
  • 42
75
votes
17 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,193
  • 3
  • 22
  • 39
52
votes
2 answers

Creating a transparent window in C++ Win32

I'm creating what should be a very simple Win32 C++ app whose sole purpose it to ONLY display a semi-transparent PNG. The window shouldn't have any chrome, and all the opacity should be controlled in the PNG itself. My problem is that the window…
adoss
  • 1,061
  • 1
  • 9
  • 9
50
votes
4 answers

C# - Faster Alternatives to SetPixel and GetPixel for Bitmaps for Windows Forms App

I am trying to teach myself C# and have heard from a variety of sources that the functions get and setpixel can be horribly slow. What are some of the alternatives and is the performance improvement really that significant? Thanks in advance! A…
purdoo
  • 852
  • 1
  • 10
  • 16
46
votes
3 answers

How to find the actual printable area? (PrintDocument)

Why is finding out this magic Rectangle so difficult? In the OnPrintPage event I have PrintPageEventArgs and I am trying to draw using the Graphics within the bounds of the maximum printable area. I have tried using PageBounds, PrintableArea,…
Trevor Elliott
  • 10,844
  • 10
  • 54
  • 97
46
votes
2 answers

Rendering controls on glass: Solution found, needs double-buffering/perfecting

I (finally!) found a way of rendering Windows.Forms controls on glass that doesn't seem to have any major drawback nor any big implementation time. It's inspired by this article from Coded, which basically explains how to natively override the…
Lazlo
  • 7,888
  • 13
  • 69
  • 113
45
votes
6 answers

How to read the Color of a Screen Pixel

Okay, I am looking for a function or something that will read the color of a certain pixel on my monitor, and when that color is detected, another function will be enabled. I figure using RGB. All help appreciated. Thank You.
Brandon
  • 475
  • 1
  • 6
  • 7
43
votes
5 answers

Measure a String without using a Graphics object?

I am using pixels as the unit for my font. In one place, I am performing a hit test to check if the user has clicked within the bounding rectangle of some text on screen. I need to use something like MeasureString for this. Unfortunately, the code…
Agnel Kurian
  • 53,593
  • 39
  • 135
  • 210
41
votes
2 answers

C# - Outputting image to response output stream giving GDI+ error

When outputting an image to the output stream, does it require temporary storage? I get the "generic GDI+" error that is usually associated with folder permission error when saving an image to file. The only thing I'm doing to the image is adding…
Daniel
  • 648
  • 1
  • 8
  • 14
37
votes
10 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
  • 36,867
  • 50
  • 163
  • 268
36
votes
4 answers

Saving image to file

I am working on a basic drawing application. I want the user to be able to save the contents of the image. I thought I should use System.Drawing.Drawing2D.GraphicsState img = drawRegion.CreateGraphics().Save(); but this does not help me for…
Victor
  • 11,135
  • 16
  • 65
  • 128
35
votes
3 answers

How to convert Bitmap to Image

I am making a median filter, the problem is manipulating pixes are only possible in Bitmap. Later I want to show the result in a PictureBox which uses Image. I can't figure out a way to to solve this...Only thing I can think of is using a Stream but…
Saeid Yazdani
  • 12,365
  • 48
  • 158
  • 270
1
2 3
99 100