system.drawing

GDI+ performance tricks

Does anyone know of any reliable (and, hopefully, extensive) books/websites that discuss GDI+ performance (beyond the obvious)? For example, I recently came across this excellent experiment. I also recently noticed that Graphics.FillPath() is way, way faster than Graphics.DrawPath(). I'd love to know what other vital bits of information...

.NET Point.IsEmpty vs IsDefined

Hi, In my UI class, a developer has the option to define a location property (type of System.Drawing.Point). By default this property is initialized to Point.Empty. The internal code that is encapsulated by the class uses the .IsEmpty of the Point property to determine if a location has been set. If the property is not empty, the x/y...

C# ImageButton Picture Resolution

I'm trying to make a simple picture thumbnail application. I've searched the web and have found fairly complicated thumbnail apps, to simple ones. I have a good one working, If I could get the ImageButton Resolution looking good. Currently, everything works fine, but the resoultion of the buttons is horrible (i've tried various width/...

System.Drawing: GDI+ is not properly initialized (​internal GDI+ error​)

Hi! An ASP.NET Web Site raises randomly this System.Drawing-error: System.Runtime.InteropServices.ExternalException: System.Drawing.Bitmap..ctor(Stream stream) System.Drawing.ToolboxBitmapAttribute..cctor() Exception information: Exception type: TypeInitializationException Exception message: The type initializer for 'Sys...

Issue in resizeing an image to thumbnail size

hi. i have an image where i am resizing the image into thumbnail size it works fine if i am using an image size[700(width)* 600(height)] orignal size lets say i have 10 images of theis size but if i use an image around size[1100*1200] orignal size it resize the image into thumbnail but doesnot match the size of...

How to prevent InvalidOperationException when using System.Drawing.Graphics?

I am using the System.Drawing.Graphics.DrawLines(Pen pen, PointF[] points) method in a multithreaded application, but the System.Drawing.Graphics isn't shared between threads. Why it keeps throwing the System.InvalidOperationException: The object is currently in use elsewhere ? ...

.Net RTF(or)HTML to Image

In .Net (C#) server process, i want to generate image with lot of rich text (with paragraphs, font style, etc.. ). The richtext can be described using RTF or HTML. Is there any way to convert RTF/HTML to a image ? Since it is a server process, i want to avoid windows forms controls. ...

Creating Visio look-a-like diagrams programatically

I need to programatically create Visio look-a-like diagrams as a drawing. Mostly we are going to create network layout diagrams similar to this one. Is there a component that could speed-up the development or some technique we could use? Generally we could do this on our own via System.Drawing, but this might get tricky for more comple...

Problem with CreateGraphics and drawing strings

C# WinForms CreateGraphics Problem The control below draws a string in a rectangle. On mouse move there is a hit test on the string rectangle, and the string is redrawn via CreateGraphics. The irritating problem is that the text is not drawn the same as in the Paint handler; it appears to be displaced by about 1 pixel, and the effect is...

Can I "draw"/create an image with a given text with powershell?

Hi, I just wondered if it would be possible to create a small, simple jpg, png, gif with a given Text in powershell: e.g: a small square, 250px × 61px, yellow background and black text on it: "Test" Can I do this with "System.Drawing.Image"? Thanks ...

Optimising PNG output from System.Drawing in .Net

Hi, I have a routine which reads in an image, resizes it and positions it on a new background (brand new bitmap, just the size is set). This all works absolutely perfectly, but now I would like to reduce the size of the PNGs it outputs - if I output jpegs, I get the ~4K or so file size I expect, but my PNGs are more than 30K in size. ...

Error using Icon.ExtractAssociatedIcon

I'm attempting to load an icon based on a selected file: Icon iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(filename); When I run this code locally through VS, everything works fine. However, after I deploy/install the application that contains this code, I get an error message: "[My Program] - Unable to locate Component: ...

Out Of Memory exception on System.Drawing in a Windows Service

Hi, I am getting in out of memory exception while using system.drawing intensively in my windows service. here is a part of my code: FileStream fs = new FileStream(ImagePath, FileMode.Open, FileAccess.Read); img = (Image)Image.FromStream(fs).Clone(); The exception is not only raised in this point, it is also raised in other points so...

Convert an Icon to IPicture in .NET 4.0?

One of the standard and (somewhat) supported answers was to use Support.IconToIPicture from the Microsoft.VisualBasic.Compatibility assembly. However, in .NET 4.0, "This API is now obsolete". Yes, there are various solutions out there, but I would think that if Microsoft was obsoleting this method, there would be another "supported" al...

Using System.Drawing, how can I draw something that imitates the effect of a yellow highlighting marker?

I want what's "behind" the yellow to show through. EDIT 1: But, if I'm drawing on "white", I'd like the marker color to retain its pure yellowness. EDIT 2: @Kevin's answer is probably correct, and I marked it correct, even though I didn't code it up. In my code, I'm settling for @Guffa's answer, using Color.FromArgb. ...

System.Drawing.Icon constructor throwing "Operation completed successfully" exception

On a Windows XP machine, the following code is throwing a System.ComponentModel.Win32Exception with the message "The operation completed successfully" System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico"); I can stop the program crashing with try { System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico"); } catch(S...

Drag and drop rectangle in C#

I want to know how to draw rectangle in C# and make it dragged and dropped in the page here my code to draw it but I cannot drag or drop it. public partial class Form1 : Form { public bool drag = false; int cur_x, cur_y; Rectangle rec = new Rectangle(10, 10, 100, 100); public Form1() { InitializeComponent(); ...

Silverlight 4.0: How to convert byte[] to image?

public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length)...

Three System.Drawing methods manifest slow drawing or flickery: Solutions? or Other Options?

I am doing a little graphing via the System.Drawing and im having a few problems. I'm holding data in a Queue and i'm drawing(graphing) out that data onto three picture boxes this method fills the picture box then scrolls the graph across. so not to draw on top of the previous drawings (and graduly looking messier) i found 2 solutions...

C#: Drawing only a portion of a path

I have a series of points in a GraphicsPath; for our purpose lets assume its the outline of an uppercase B. I want to be able to be able to draw only the bottom portion that would resemble an uppercase L. I'd like to be able to select a window of points from the GraphicsPath. Is there a handy way to do this without doing point interpo...