gdi+

Drawing Transparent Images

I'm writing a CSS sprite engine in C#, however I'm having a few issues. I create the master image, set all the properties to that then iterate the sprites and draw those to the master image. However when I come to save the master image it only appears to be just the empty master image with transparent background and none of the sprites. ...

Graphics.DrawImage Doesn't Always Paint The Whole Bitmap?

I have run into a strange problem when using Graphics.DrawImage. When using e.Graphics.DrawImage(Image, Point) in OnPaint to paint a bitmap 'buffer' on the control, it appears that parts of the image are omitted. The buffer is populated in a helper method which draws directly onto the Bitmap using a Graphics constructed from it. Wh...

Optimizing map drawing

Hello, I have problem optimizing drawing Google-like map. It works OK for hundreds of points, but when it comes to larger amounts like thousands it gets fuzzy and slow. Also unzoomed it looks weird. I'd like to know how to optimize drawing algorithm to draw fewer places so it looks like unzooming on Google Maps. However I also draw lin...

Save HICON as a png

I am using IShellItemImageFactory to extract the icon for a file. I was able successfully extract it and show it in a dialog using SendDlgItemMessage(hDlg,IDC_STATIC2, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hicon); see the output: click here The issue is when I am saving this as a file(PNG format) using GDI+ the gradients are not preservi...

Windows: Getting glyph outlines for substitution characters from other fonts

I need to render fonts into a 3d game world, so I use the GetGlyphOutline outline function to get the glyph shapes to render into a texture. However, I want to be able to handle the case where characters are not present in the given font (as is often the case for asian other other international text). Windows text rendering will automati...

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...

GDI+: Limitations of Paths and Regions

Are there limits/differences when performing GDI operations on off-screen objects like paths/regions as compared to performing the same operations on the display? What limits can I expect when performing graphics operations on a region/path as opposed to performing them directly on the display? When performing GDI operations on GDI reg...

[GDI+] Performance difference between DrawLine and DrawLines ?

Im using GDI+ in C++ to draw a chart control. I want to know if there is any performance difference between the above 2 functions. I am not lazy to write code for DrawLines() but it is that doing so makes my code complex. So im weighin the chances of whether to make code execution faster at the expense of reducing readability and potenti...

How to measure the pixel width of a digit in a given font / size (C#)

I am trying to calculate the pixel width of Excel columns, as described in this post, using the official formula from the OpenXML specification. However, in order to apply this formula, I need to know the Maximum Digit Width of the Normal font, which is the pixel width of the widest numeric digit. The OpenXML specification gives this exa...

Convert multiple byte[] to multipage tiff equivalent of Image.SaveAdd without GDI+

I am working on a system that stores many images in a database as byte[]. Each byte[] is a multi page tiff already, but I have a need to retrieve the images, converting them all to one multi page tiff. The system was previously using the System.Drawing.Image classes, with Save and SaveAdd - this was nice in that it saves the file progres...

Moving a picturebox with a timer

Hi, I'm trying to move a picturebox in a containing control by changing its Top and Left properties every 20ms. On a black background it's a bit smoother but when assigning a BackgroundImage to the control, the picturebox leaves a trail behind it until the control is redrawn a few seconds later, slows down abruptly then launches forward...

C# image drawing colours are incorrect

I have a source bitmap that is 1x1 and I am trying to take that image and draw it to a new bitmap. The source bitmap is all red, but for some reason the new bitmap ends up with a gradient (see image). Using the code below, shouldn't the new bitmap be completely red? Where is it getting the white/alpha from? private void DrawImage() { ...

Shorten a line by a number of pixels

I'm drawing a custom diagram of business objects using .NET GDI+. Among other things, the diagram consists of several lines that are connecting the objects. In a particular scenario, I need to shorten a line by a specific number of pixels, let's say 10 pixels, i.e. find the point on the line that lies 10 pixels before the end point of t...

Windows Aero: What color to paint to make "glass" appear?

What color must i paint in the client area in order to make glass appear? i've extended the frame of my form into the client area using: DwmExtendFrameIntoClientArea(self.Handle, margins); i cannot find any official documentation from Microsoft on what color and/or alpha the DWM will look for to replace with glass. The documentation ...

How to debug GDI+ in c#?

i have a user control, and it's not drawn correctly, how to debug the drawing? If i set break point, the control will get blocked, i can't see the drawing result instantly? any idea? ...

Ghost-borders ('ringing') when resizing in GDI+

What happens (only noticeable on certain images) is I will see a 1 pixel white border that is inset one pixel. It seems to happen in areas that are light but not white (e.g. the sky). It is similar to when something is oversharpened and a ghost border can be seen next to high contrast edges. Here is the repro code that reproduces it per...

GdipCreateBitmapFromStream change of contract on Windows 7?

We have a perfectly functional app that just broke on Windows 7 because (the GDI+ primitive) GdipCreateBitmapFromStream refuses JPEG images presented to it (without problem on XP and even Vista). We don't directly call GDI+, we call the documented ATL CImage class, and it calls that, and gets the error. It's our own OLE stream implemen...

Crashing with gdiplus(new Bitmap)

My application is crashing on Bitmap* image = new Bitmap(hicon) in a old Win XP installation. The stack trace is showing it is in gdiplus.dll, the version of the dll in this system is 5.1.3097.0. I tried with a newer version of dll (5.1.6001.0) and it was working fine. Is this a bug with GDI Plus? or am I doing something wrong. What is ...

Is it possible to hook into GDI+ and save all strings sent to DrawString?

I need to get a large table (300K+ rows) from an application and there is no export function. After a lot of unsuccessful attempts I'm left with a Copy Paste macro that goes one row at a time. If there is a way to get the strings as they are drawn I could get a page(40 rows) at once. ...

Can't draw on Internet Explorer

I have the following code which draws a square on the main window of another process: private void DrawOnWindow(string processname) { IntPtr winhandle = GetWindowHandle(processname); Graphics grph = Graphics.FromHwnd(winhandle); grph.DrawRectangle(Pens.Red, 10, 10, 100, 100); } private IntPtr GetWindowHandle(string windowNa...