Tag Archives: gdi+

Increase or Decrease the GDI+ Graphic’s Quality and Speed using VB.NET, VB 2010, and Higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Usually by default, the GDI+ Library is set for higher speed rendering and lesser quality output. Thankfully they give control over a few of the quality settings for rendering images, drawing, filling, etc..  But one of the current problems with GDI+ is that it is not GPU hardware accelerated like the original GDI Classic API library. Since many users computers are very powerful this day and age, it may not be to much of a concern. But there are still those users with slower computers and if you set the graphic quality to high it will weigh down (slow down) their computer. So sometimes you may have to make a compromise between quality and performance. Or give the user the option to increase/decrease the quality manually. This little article is basically just going to show some of the the quality based features of GDI+ for either increasing or decreasing the quality and/or performance. Obviously if your not a VB.NET beginner, you may already know of these features and would not benefit from this post. 🙂


This article is mainly to highlight some features you can use to increase/decrease the quality/performance of your graphics rendering. I will not go in-depth on the features and you can find resources on exactly what each feature means and/or does at Microsoft’s website.

Text Rendering…

Quite often you may need to draw text using GDI+ in your projects. There is a little feature available that can have a pretty big effect on the quality of your text. GDI+ has a feature that has a big effect on Text rendering. Its a property called: “TextRenderingHint” in the Graphics Class. If you check out that property under the ObjectBrowser(Press F2 is view) there are a few enum’s available to set this property. You can specify SystemDefault rendering up to AntiAliasGridFit and even ClearTypeGridFit. In my opinion I like the ClearTypeGridFit rendering effect and usually draw text with it. But AntiAlias is also higher quality setting and will ‘Smooth’ out the edges/corners of your text to make it look better. But as you may already know, the ClearType and AntiAlias settings WILL use more resources. So you may want to use SingleBitPerPixel rendering. Which will be low quality, high speed rendering. You will probably want to tinker with the 6x(Six) TextRenderingHint settings. Below is a simple example…

        'Either of these settings will give you higher quality but at the cost of performance.
        'High quality rendering
        g.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit

        'High quality rendering
        g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit

        'This will give somewhat lower quality but better performance.
        g.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixel


Line Based Rendering…

Usually by Default when you draw lines it is using High Speed rendering and not High Quality. Thankfully GDI+ has that covered. By Default, at least on my computer drawing lines is very jagged and rough. So you very well may want to ‘Smooth” out your drawn lines. Thats where the Graphics.SmoothingMode Property comes into play. There are a few settings available depending on the speed/quality you want. Obviously the “HighQuality” setting should be the best out of the settings, while HighSpeed should be the worst quality setting. There are other settings available like “AntiAlias” and “Default”. If you hate jagged lines and curves or edges, then you will want to use either the “AntiAlias” setting or the “HighQuality” setting. If you want the quickest rendering then use “HighSpeed“. On my computer at least the “Default” setting is very low quality. So you may Not want to use it. 🙂

Just a note – I am not really able to see to much of a difference between using “AntiAlias” and “HighQuality”. But that definitely doesn’t mean they are the same. “HighQuality” will be slower to render and “AntiAlias” should be a little quicker to render.

To set the quality for your line/shape,ect.. drawing just set the SmoothingMode property as seen below…

        'Simply declare a Graphics object.
        Dim g As Graphics

        'This will give the best looks available but also the worst performance.
        g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

        'This will give the worst looks but the Best performance.
        g.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed


Image Based Rendering

The last rendering in this article is for Drawing Images. There are a couple features available for doing “HighSpeed” and/or “HighQuality” Image rendering. The first to go over is: “InterpolationMode”. You would want to use this mode for doing Image Scaling and/or Rotating. There are quite a few settings you can choose in this Property. From “Low” quality rendering up to “HighQualityBiCubic” rendering. As the names suggest, the “Low” setting will give the Best performance but the Worst quality. Likewise, “HighQualityBiCubic” should give the Best quality but the Worst performance. There are many settings available if you want to reach a compromise between quality and speed. Like specifying “Bilinear” only rendering or “BiCubic” rendering. Use the different settings till you get the results your after. “CompositingQuality” Is another feature related to Image rendering quality.

Below is a explanation from Microsoft on Compositing Images.

Compositing is done during rendering when the source pixels are combined with the destination pixels to produce the resultant pixels. The quality of compositing directly relates to the visual quality of the output and is inversely proportional to the render time. The higher the quality, the slower the render time. This is because the higher the quality level, the more surrounding pixels need to be taken into account during the composite.

The “AssumeLinear” setting apparently gives you a ‘balance’ between quality and speed. So use this setting if you want alittle of both. Below is a simple example of setting the Compositing quality…

        'This will give you high quality but also the worst performance.
        g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality

        'This will give lower quality but the Best performance.
        g.CompositingQuality = Drawing2D.CompositingQuality.HighSpeed

That’s about it. Take Care 🙂


Draw a Line on a WindowsForm using VB.NET and Higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Shows how to use Visual Basic.NET and GDI+ to draw a line on the form.

        'Draws a line on the form in .NET
        Dim bit As Bitmap = New Bitmap(Me.Width, Me.Height)

        Dim g As Graphics = Graphics.FromImage(bit)

        Dim myPen As Pen = New Pen(Color.Blue, 3)

        Me.CreateGraphics.DrawLine(myPen, 0, 0, Me.Width, Me.Height)

Clear the Drawing Surface using VB.NET and GDI+

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Clears the drawing surfice using GDI+ and VB.NET

        'Change e to whatever your graphics variable is.
        'Change Black to whatever you want the color to be

Add all Known GDI+ Web Colors to a Combobox or Listbox control.

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This will add the list of all known colors to a combobox or listbox control.

Imports System.Drawing


Dim kColor As KnownColor

For kColor = KnownColor.AliceBlue To KnownColor.YellowGreen