System Colours in .NET

Ever wondered what all those AliceBlue or LemonChiffon colours (or color if you are American and googling *HINT HINT*) actually look like? Wondered what their Hexadecimal code is so you can decide which colours to use in your website? screencapture-web-archive-org-web-20070507033844-http-www-mdibb-net-net-system_colours_in_net-1471675958847
Well you might not have but I have, and because I am often trying to remember what each colour is, here is a handy little reference of all of the System colours that are lurking in the System.Drawing.Color structure!

C# Data Types

Below is a table showing the minium and maximum values (i.e. the range) of the most common data types in C#. These values are based on those found in the MSDN docs. In MSDN some of these values are kinda spread out in various different pages so I’ve put them together into a single table for easy comparison as I’ve found the MSDN site pretty slow to browse sometimes.

.NET Type Integral Type Range Size
System.Byte byte 0 to 255 unsigned 8bit integer
System.SByte sbyte -128 to 127 signed 8bit integer
System.Char char U+0000 to U+ffff unicode 16-bit character
System.Int16 short -32,768 to 32,767 signed 16-bit integer
System.UInt16 ushort 0 to 65,535 unsigned 16-bit integer
System.Int32 int -2,147,483,648 to 2,147,483,647 signed 32-bit integer
System.UInt32 uint 0 to 4,294,967,295 unsigned 32-bit integer
System.Int64 long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 signed 64-bit integer
System.UInt64 ulong 0 to 18,446,744,073,709,551,615 unsigned 64-bit integer
System.Single float ±1.5 × 10-45 to ±3.4 × 1038 (approx.) 7 digit precision
System.Double double ±5.0 × 10-324 to ±1.7 × 10308 (approx.) 15-16 digit precision
System.Decimal decimal ±1.0 × 10e-28 to ±7.9 × 10e28 (approx.) 28-29 significant digits

MySQL2CSV – simple online database dumps to CSV using PHP

I’ve often had the need to quickly and easily take a copy of a database table. Sometimes I am making a backup, other times I just want the data in CSV (Comma Separated Value) format so I can easily import it into another database or programme and so on.

There are ways to do this with various things like web-based MySQL tools, or using the command line directly but sometimes nothing is quicker than a simple FTP client! So I put together this simple PHP script that will access a table and dump all of its rows and show me the CSV in a text box, or just let me save off the entire page for use later. This could be used as a really simple backup script for a database by using a combination of cron and wget to take a quick copy without any human intervention!

Click below to view some example output. Feel free to take and use this script as you please – please note that it is just a quick and dirty little script I knocked up, there is no warranty and I cant vouch for its fitness for a particular purpose.

MySQL2CSV Usage Instructions

To use this script, all you need to do is edit the first few lines of the PHP file to reflect your database settings. The lines you need to look at are the ones that look a bit like these:

$Settings[‘dbusername’] = “username”;
$Settings[‘dbpassword’] = “password”;
$Settings[‘dbhost’] = “localhost”;
$Settings[‘dbport’] = “3306”;
$Settings[‘dbname’] = “databasename”;
$Settings[‘dbtable’] = “tablename”;

Once you have provided the correct details for the script, all you then need to do is upload the file to your server and then view the page from there.


Faster pixel manipulation with GetPixel and SetPixel in .NET

If you have been playing around much with VB.NET or C#, chances are you have had a go at manipulating images using the System.Drawing.Bitmap namespace. The Bitmap class is great and gives us a nice easy set of functions for finding out the colour of a pixel at a given coordinate, and changing it if we want. But if you are reading this now you’ve probably found out – like I did – that this is really really slow!

The reasons for this being so slow are deeply rooted in the .NET runtime (in particular the way that it manages code so that it is “safe”) that I’m not going to go into now. By using a fairly simple technique we can get around this problem and use the Bitmap in an “unsafe” way to get direct access to the memory, and speed things up a lot along the way.

he code I am going to show you below was based on a MSDN article by Eric Gunnerson where he showed how the “unsafe” technique can be used to make an image greyscale. I’ve basically just modified his code into a general purpose class, so you can just drop this class in and use its faster GetPixel and SetPixel methods how you would with the Bitmap class.

I’ve not done any proper benchmarks here, but what was taking about 7 seconds with the original and slow GetPixel methods, now happens pretty much instantly (certainly quicker than I could time manuaully) so its pretty fast.

The FastBitmap Class

This is the main code – a simple class that deals with the “unsafe” memory for the bitmap. Note that if you try using this in your project, you’ll need to use the “/unsafe” compiler flag to get it to compile – to set this up in Visual Studio, just right click on the project in the solution explorer, go to “Properties”, select the “Build” tab and tick the “Allow unsafe code” box; if you are using the command line or some other IDE, just stick the “/unsafe” switch in compilation command line somewhere.

using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace Image {
public unsafe class FastBitmap {

public struct PixelData {
public byte blue;
public byte green;
public byte red;

Bitmap Subject;
int SubjectWidth;
BitmapData bitmapData = null;
Byte* pBase = null;

public FastBitmap(Bitmap SubjectBitmap) {
this.Subject = SubjectBitmap;
try {
} catch (Exception ex) {
throw ex;


public void Release() {
try {
} catch (Exception ex) {
throw ex;

public Bitmap Bitmap {
get {
return Subject;

public void SetPixel(int X, int Y, Color Colour) {
try {
PixelData* p = PixelAt(X, Y);
p->red = Colour.R;
p->green = Colour.G;
p->blue = Colour.B;
} catch (AccessViolationException ave) {
throw (ave);
} catch (Exception ex) {
throw ex;

public Color GetPixel(int X, int Y) {
try {
PixelData* p = PixelAt(X, Y);
return Color.FromArgb((int)p->red, (int)p->green, (int)p->blue);
} catch (AccessViolationException ave) {
throw (ave);
} catch (Exception ex) {
throw ex;

private void LockBitmap() {
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = Subject.GetBounds(ref unit);
Rectangle bounds = new Rectangle((int)boundsF.X,

SubjectWidth = (int)boundsF.Width * sizeof(PixelData);
if (SubjectWidth % 4 != 0) {
SubjectWidth = 4 * (SubjectWidth / 4 + 1);

bitmapData = Subject.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
pBase = (Byte*)bitmapData.Scan0.ToPointer();

private PixelData* PixelAt(int x, int y) {
return (PixelData*)(pBase + y * SubjectWidth + x * sizeof(PixelData));

private void UnlockBitmap() {
bitmapData = null;
pBase = null;

Using FastBitmap

I tried to make this class as simple to use as possible – you should just be able to drop it in and use the GetPixel and SetPixel methods as you would with any normal Bitmap.

You simply need to provide a normal Bitmap object to the constructor, like so:

FastBitmap FBitmap = new FastBitmap(MyOriginalBitmap);

After that you can just use the usual SetPixel and Get Pixel methods with the usual System.Drawing.Color arguments and so on. Finally when you are done with the FastBitmap, you should release it like so:


This will basically “tidy up” the memory used by the unsafe mode and a few bits and pieces inside the class.
Please note that although I have tested this class, I cannot vouch for its reliability. It seems pretty stable and reliable to me, and I have put in some basic exception handling that you should surround with try catch blocks but it might do some strange things, particularly if you are dealing with different thre


Welcome to

Please use the Articles link to view all of the articles on this site, or use the category links at the top right of the page to view all articles in a particular category.

Also at the top right of the page is a search box, which can be used to search all articles on the site.

Some of you may be interested to know that I am putting together a blog about web development, web design, seo and all that kind of stuff which you may want to check out. Thanks!