Category Archives: graphics

Convert a Rectangle into a RectangleF and vice versa in C#

The RectangleF structure has an overloaded assignment operator = that lets you simply set a RectangleF equal to a Rectangle, so converting a Rectangle into a RectangleF is easy. That makes sense because converting from Rectangle to RectangleF is a … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , | Leave a comment

Make a hangman game in C#

Special thanks to Jeff Scarterfield for the skeleton drawing used by the program. This example builds a simple hangman game that uses the dictionary created by the example Use LINQ to select words of certain lengths from a file in … Continue reading

Posted in algorithms, files, games, graphics, strings | Tagged , , , , , , , , , , , , | Leave a comment

Draw a golden spiral in C#

This example shows how to draw a golden spiral (or phi spiral) in C#. The example Draw a nested series of golden rectangles in C# draws nested rectangles and connects their corners to make a square “spiral.” This example makes … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , , | 3 Comments

Draw a nested series of golden rectangles in C#

This program draws golden rectangles, rectangles whose side ratio is equal to φ. For information on φ, see Examine the relationship between the Fibonacci sequence and phi in C#. The program first draws a golden rectangle. It then removes the … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , | 2 Comments

Examine the relationship between the Fibonacci sequence and phi in C#

The golden ratio (also called the golden mean, golden section, or divine proportion) is a number that pops up in a surprising number of places in geometry and nature. This number is also called φ (phi, pronounced either “fee” or … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Make light pixels transparent in an image in C#

Recently I had an image and I wanted to make all of the light pixels transparent. Ideally I could simply make the white pixels transparent, but the image was scanned so few of the pixels were pure white. What I … Continue reading

Posted in graphics, image processing | Tagged , , , , , , , , , , , | Leave a comment

Draw a smiley face with WPF in C#

Often I need to use images for demonstration purposes or for a book, and a smiley face makes a neutral, pleasant image. This example shows how to draw a smiley face with XAML and WPF, and then save an image … Continue reading

Posted in drawing, graphics, image processing, wpf, XAML | Tagged , , , , , , , , , , , , , , | Leave a comment

Rotate images that are scaled in C#

The example Interactively rotate images in C# lets you click and drag to rotate images but it doesn’t always work well if the image you are rotating is too big to fit on the screen. The example Rotate images inside … Continue reading

Posted in algorithms, graphics, image processing, transformations | Tagged , , , , , , , , , , , , , , | 1 Comment

Rotate images inside a scrolled panel in C#

The example Interactively rotate images in C# lets you click and drag to rotate images. Unfortunately it doesn’t work well with images that are too big to fit on the screen. If an image is too big, the program lets … Continue reading

Posted in algorithms, graphics, image processing, transformations | Tagged , , , , , , , , , , , , | Leave a comment

Explore the Visual Studio Image Library in C#

This example explains where you can find standard images in the Visual Studio Image Library that you can use in your applications. The example Give transparent backgrounds to images displayed on buttons in C# explains how to make some pixels … Continue reading

Posted in controls, graphics | Tagged , , , , , , , , , , , , | Leave a comment