This page is the starting point for all code samples. As I discover something new/interesting I’ll be creating code samples explaining a specific topic. These samples are not intended to be full on applications, but rather components that can be used in applications. If you would like me to create a code sample on a specific topic please drop me a comment here, or reach me via twitter @DefaultSoftware All code is released under the Ms-PL license.
Navigate to an article by clicking the relevant thumbnail image.
Article List
Windows Forms Applications with non standard borders
Article and sample code illustrating how to create Windows Forms applications with customized borders implemented using GDI.
Extending ConfigurationManager – Get values by type
Short Code Sample explaining how to read values from Application Configuration Files without having to cast/parse by hand.
C# How to: Determine free space on a drive
An article based on using the System.IO.DriveInfo class to determine the amount of space not in use on a particular logical disk drive.
C# How to: Drawing in GDI with Opacity/Alpha components
A discussion accompanied by a code sample illustrating drawing two dimensional shapes and text with ARGB colours.
C# How to: Changing a File’s read only attribute
This article provides a discussion on how to determine whether a file is read only or not, provides three different methods of setting a file to read only and provides three different methods of negating a file’s read only status. Full code sample and source code download included.
C# How to: Implementing Xml Serialization through a generic extension method
The purpose of this article is to explore the implementation of object Xml serialization by means of a single extension method supporting generic types.
C# How to: Implementing Generic Xml Deserialization by extending the string class
The purpose of this article is to illustrate Deserializing Xml data to object data that resides in application memory. Additionally this article details implementing generics, resulting in a single method being able to deserialize multiple object types. This article relates to the article: C# How to: Implementing Xml Serialization through a generic extension method
C# How to: Deep copy objects using Binary Serialization
This article will illustrate how to create deep copies of an object by making use of binary serialization implemented in the form of an extension method with generic type support. A short discussion is included on the differences between shallow copy and deep copy.
C# How to: Generate a Web Service from WSDL
Web Service Definition Language (WSDL) is an Xml based schema that exactly details the custom data types and web service methods exposed by a web service. Developers usually generate web service client proxy code in order to call into web services. Since WSDL is an exact description of a web service it is also possible to generate code that represents the service in the form of web method stubs. This article illustrates how to generate a web service from WSDL.
C# How to: Using Microsoft Kinect with Windows Forms
This article illustrates a basic introductory level explanation of the steps required to interface with the Microsoft Kinect for Windows sensor using the Kinect for Windows Sdk implemented in a Windows Forms application.
C# How to: Check if a Tcp Port is in use
This article features a short illustration of how to determine if a network port is already in use.
C# How to: Encoding Bitmaps to Base64 strings
This article explores encoding Bitmap images to Base64 strings. Encoding is implemented by means of an extension method targeting the Bitmap class.
C# How to: Decoding/Converting Base64 strings to Bitmap images
This article details how to decode or convert Base64 encoded strings back into Bitmap images by means of extending the string class. Note: This article is an update that builds upon the article: C# How to: Encoding Bitmaps to Base64 strings
C# How to: Image filtering by directly manipulating Pixel ARGB values
In this article we discover creating basic image filters implemented by directly manipulating the ARGB colour values associated with an image’s pixels. The different types of filters discussed are: Grayscale, Transparency, Image Negative and Sepia tone. All filters are implemented as extension methods targeting the Image class, as well as the Bitmap class as the result of inheritance and upcasting.
C# How to: Image filtering implemented using a ColorMatrix
This article is based around creating basic Image filters. The different types of filters discussed are: Grayscale, Transparency, Image Negative and Sepia tone. All filters are implemented as extension methods targeting the Image class, as well as the Bitmap class as the result of inheritance and upcasting.
Note: This article is a follow up to C# How to: Image filtering by directly manipulating Pixel ARGB values. The previously published related article implements image filtering by performing calculations and updating image pixel colour component values namely Alpha, Red, Green and Blue. This article achieves the same image filtering through implementing various ColorMatrix transformations, in essence providing an alternative solution. For the sake of convenience I have included the pixel manipulation extension methods in addition to the ColorMatrix extension methods detailed by this article.
C# How to: Encoding Base64 Thumbnails
This article details how to read Image files from the file system, create thumbnails and then encoding thumbnail images to Base64 strings.
C# How to: Blending Bitmap images using colour filters
In this article we explore how to combine or blend two Bitmap images by implementing various colour filters affecting how an Image appear as part of the resulting blended image. The concepts detailed in this article are reinforced and easily reproduced by making use of the sample source code that accompanies this article.
C# How to: Bitmap Colour Substitution implementing thresholds
This article is aimed at detailing how to implement the process of substituting the colour values that form part of a Bitmap image. Colour substitution is implemented by means of a threshold value. By implementing a threshold a range of similar colours can be substituted.
C# How to: Generating Icons from Images
This article illustrates the process of generating icon files (*.ico) from user specified input images. The accompanying sample source code implements a Windows Forms application, allowing for easily testing the icon generation process.
C# How to: Swapping Bitmap ARGB Colour Channels
The intention of this article is to explain and illustrate the various possible combinations that can be implemented when swapping the underlying colour channels related to a Bitmap image. The concepts explained can easily be replicated by making use of the included sample application.
C# How to: Bitmap Pixel manipulation using LINQ Queries
In this article we explore manipulating a Bitmap image’s underlying pixel data. The process of Pixel data manipulation at its core feature the implementation of Linq Queries targeting raw pixel data.
C# How to: Linq to Bitmaps – Partial Colour Inversion
In this follow up article we further explore manipulating a Bitmap image’s underlying pixel data. This article is part 2 of the Linq to Bitmaps series, we’ll be focussing on partial colour inversion using Linq queries. This article was published as a follow up to: C# How to: Bitmap Pixel manipulation using LINQ Queries.
C# How to: Bitmap Colour Balance
This article explores the concept of manipulating the Colour Balance of a Bitmap image. Colour Balance values are updated by directly manipulating a Bitmap’s underlying pixel data, no GDI drawing code required.
C# How to: Bi-tonal Bitmaps
The purpose of this article is to explore and illustrate the concept of creating bi-tonal bitmap images. Colour images are manipulated in such a fashion to only express two colours. The colours expressed are configurable. A threshold value determines which of the two configured colours will be applied to a pixel.
C# How to: Bitmap Colour Tint
The purpose of this article is to illustrate the tasks required when implementing a colour tint on a Bitmap image. The various Bitmap manipulation operations detailed in this article are all exclusively implemented by processing raw pixel data. No traditional GDI+ drawing operations are required in achieving the objective of this article
C# How to: Bitmap Colour Shading
The objective of this article is focussed on exploring the concept of applying Colour Shading to Bitmap images. The various Bitmap manipulation operations detailed in this article are all exclusively implemented by processing raw pixel data. No traditional GDI+ drawing operations are required in implementing Bitmap Colour Shading.
C# How to: Image Solarise
The focus of this article is set on exploring the concept of Image Solarisation. In this article the tasks required to perform Image Solarisation are entirely implemented on pixel data level. Image manipulation is only implemented in the form of updating the individual Alpha, Red, Green and Blue colour components expressed by Image pixels.
C# How to: Image Contrast
Adjusting the contrast of an Image is a fairly common task in image processing. This article explores the steps involved in adjusting image contrast by directly manipulating image pixels.
C# How to: Bitwise Bitmap Blending
In this article you’ll find a discussion on the topic of blending Bitmap images into a single Image. Various possible methods can be employed in blending images. In this scenario image blending is achieved through means of bitwise operations, implemented on individual colour components Red, Green and Blue.
C# How to: Image Arithmetic
The objective of this article is to illustrate Image Arithmetic being implemented when blending/combining two separate images into a single result image. The types of Image Arithmetic discussed are: Average, Add, SubtractLeft, SubtractRight, Difference, Multiply, Min, Max and Amplitude.
C# How to: Image Convolution
This article is intended to serve as an introduction to the concepts related to creating and processing convolution filters being applied on images. The Convolution filters discussed are: Blur, Gaussian Blur, Soften, Motion Blur, High Pass, Edge Detect, Sharpen and Emboss.
C# How to: Image Edge Detection
The objective of this article is to explore various edge detection algorithms. The types of edge detection discussed are: Laplacian, Laplacian of Gaussian, Sobel, Prewitt and Kirsch. All instances are implemented by means of Image Convolution.
C# How to: Difference Of Gaussians
In this article we explore the concept of Difference of Gaussians edge detection. This article implements image convolution as a means of achieving Gaussian blurring. All of the concepts explored are implemented by accessing and manipulating the raw pixel data exposed by an image, no GDI+ or conventional drawing code is required.
C# How to: Image Median Filter
The objective of this article is focussed on providing a discussion on implementing a Median Filter on an image. This article illustrates varying levels of filter intensity: 3×3, 5×5, 7×7, 9×9, 11×11 and 13×13.
C# How to: Image Unsharp Mask
The purpose of this article is to explore and illustrate the concept of Image Unsharp Masking. This article implements image convolution in the form of a 3×3 Gaussian Blur, 5×5 Gaussian Blur, 3×3 Mean filter and a 5×5 Mean filter.
C# How to: Image Colour Average
This article’s intension is focussed on providing a discussion on the tasks involved in implementing Image Colour Averaging. Pixel colour averages are calculated from neighbouring pixels.
C# How to: Image Erosion and Dilation
The purpose of this article is aimed at exploring the concepts of Image Erosion, Image Dilation, Open Morphology and Closed Morphology. In addition this article extends conventional Image Erosion and Dilation implementations through partial colour variations of Image Erosion and Dilation.
C# How to: Morphological Edge Detection
The objective of this article is to explore Image Edge Detection implemented by means of Image Dilation and Image Erosion morphological filters. In addition we explore the concept of Image Sharpening implementing morphological edge detection.
C# How to: Boolean Edge Detection
The purpose of this article is to detail Boolean Function Based Edge Detection. The Image filtering implemented in this article occurs on a per pixel basis. The implementation relies on linear algebra. No GDI+ or traditional drawing methods are required.
C# How to: Gradient Based Edge Detection
This article provides a technical discussion exploring the topic of Gradient Based Edge Detection and related aspects. Several filtering options are illustrated and explained ranging from pure black and white edge detection to image sharpening.
C# How to: Image Cartoon Effect
In this article we explore the tasks related to creating a Cartoon Effect from images which reflect real world non-animated scenarios. When applying a Cartoon Effect it becomes possible with relative ease to create images appearing to have originated from a drawing/animation.
C# How to: Sharpen Edge Detection
It is the objective of this article to explore and provide a discussion based in the concept of Edge Detection through means of Image Sharpening. Illustrated are various methods of image sharpening and in addition a Median filter implemented in image noise reduction.
C# How to: Calculating Gaussian Kernels
This article’s purpose is to explain and illustrate in detail the requirements involved in calculating Gaussian Kernels intended for use in image convolution when implementing Gaussian Blur filters. This article’s discussion spans from exploring concepts in theory and continues on to implement concepts through C# sample source code.
C# How to: Image Blur
This article serves to provides an introduction and discussion relating to Image Blurring methods and techniques. The Image Blur methods covered in this article include: Box Blur, Gaussian Blur, Mean Filter, Median Filter and Motion Blur.
C# How to: Image Transform Rotate
This article provides a discussion exploring the concept of image rotation as a geometric transformation. In addition to conventional image rotation this article illustrates the concept of individual colour channel rotation.
C# How to: Image Transform Shear
This article is focussed on illustrating the steps required in performing an image Shear Transformation. All of the concepts explored have been implemented by means of raw pixel data processing, no conventional drawing methods, such as GDI, are required.
C# How to: Compass Edge Detection
This article’s objective is to illustrate concepts relating to Compass Edge Detection. The edge detection methods implemented in this article include: Prewitt, Sobel, Scharr, Kirsch and Isotropic.
C# How to: Oil Painting and Cartoon Filter
This article illustrates and provides a discussion and implementation of Image Oil Painting Filters and related Image Cartoon Filters.
C# How to: Stained Glass Image Filter
This article serves to provides a detailed discussion and implementation of a Stained Glass Image Filter. Primary topics explored include: Creating Voronoi Diagrams, Pixel Coordinate distance calculations implementing Euclidean, Manhattan and Chebyshev methods. In addition, this article explores Gradient Based Edge Detection implementing thresholds.
C# How to: Image ASCII Art
This article explores the concept of rendering ASCII Art from source images. Beyond exploring concepts this article also provides a practical implementation of all the steps required in creating an Image ASCII Filter.
C# How to: Weighted Difference of Gaussians
It is the purpose of this article to illustrate the concept of Difference of Gaussians Edge Detection. This article extends the conventional implementation of Difference of Gaussian algorithms through the application of equally sized matrix kernels only differing by a weight factor.
C# How to: Image Boundary Extraction
This article explores various image processing concepts, which feature in combination when implementing Image Boundary Extraction. Concepts covered within this article include: Morphological Image Erosion and Image Dilation, Image Addition and Subtraction, Boundary Sharpening, Boundary Tracing and Boundary Extraction.
C# How to: Image Abstract Colours Filter
This article explores Abstract Colour Image filters as a process of Non-photo Realistic Image Rendering. The output images produced reflects a variety of artistic effects.
0 Responses to “Code Samples”