This example lets you obscure parts of a picture to hide sensitive information such as names, email addresses, phone numbers, and photographs. It provides three obscuring styles: Pixelated (the area is replaced with blocks of color), Fuzzy (the area is smoothed so it appears fuzzy), and Redacted (the area is filled with black).
Press Ctrl+O to open a picture file. Then click and drag to select an area to obscure.
The program’s Tools > Parameters menu displays a parameter dialog where you can change the style of obscuring and the size of the graphical kernel used to perform fuzzing and pixelation. (Larger kernels obscure the result more.)
This example uses several techniques that are described in other examples so I won’t repeat those descriptions here. The following list summarizes some of the more useful techniques and the posts that provide more detail.
- Load images without locking their files in C#
- Use image filters to perform edge detection, smoothing, embossing, and more in C#
- Let the user select rectangular areas in an image in C#
- Save images with an appropriate format depending on the file name’s extension in C#
See those examples for details.
The new parts of the program work like this:
- When you load a picture file, the program saves the image in the variable OriginalImage.
- The program copies the original image into the variable VisibleImage and displays it.
- When you load a new file or change the obscuring parameters, the program makes a copy of the original image and saves it in variable ObscuredImage. Then:
- If the obscuring style is Pixelated or Fuzzy, the program then applies the appropriate obscuring method to the entire image in ObscuredImage. The result is a completely obscured image.
- If the obscuring style is Redacted, the program doesn’t need to do anything with ObscuredImage.
- When you click and drag to select a rectangle, the program obscures the area you select.
- If the obscuring style is Pixelated or Fuzzy, the program copies the selected part of the image from ObscuredImage to CurrentImage.
- If the obscuring style is Redacted, the program simply fills the selected rectangle with black in CurrentImage.
That’s about all there is to it. Download the example to see the details.