Monthly Archives: July 2018

Trim images in C#

This example shows how you can trim images to remove unnecessary whitespace around their edges. Sometimes when I make pictures for a book, it’s hard to tell where the edges of the picture begin, so I risk either including more … Continue reading

Posted in Uncategorized | Tagged , , , , , , , , | Leave a comment

Find Mersenne primes in C#

Mersenne primes are prime numbers of the from 2n – 1 for some integer n. For example, 22 – 1 = 4 – 1 = 3 and 3 is prime, so 3 is a Mersenne prime. This example uses a … Continue reading

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

Display a progress bar with text in WPF and C#

As is so often the case in WPF, the solution is simple after you spend a few hours figuring out what controls to use. This example uses a normal Grid control that holds a StackPanel. The following code shows the … Continue reading

Posted in controls, user interface, wpf, XAML | Tagged , , , , , , , , , , , , , | 1 Comment

Convert between ragged arrays and two-dimensional arrays

Ragged arrays are arrays that hold other arrays, as opposed to two-dimensional arrays. They are called “ragged arrays” because they work like two-dimensional arrays (or higher-dimensional arrays) where each row in the array can hold a different number of elements. … Continue reading

Posted in algorithms, arrays, extension methods, generic | Tagged , , , , , , , , , , , | Leave a comment

Perform image hashing in C#

Image hashing or (perceptual image hashing) attempts to reduce an image to a concise code that represents the image so you can compare it to other images to see if they are the same. This example uses a difference hash … Continue reading

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