TWith2Sugars

Feb 23

Want the directory of a .Net app?

Then use this line:

AppDomain.CurrentDomain.BaseDirectory

Feb 17

likes 28 Weeks Later on Boxee

Xml Serialisation (Serialization) in C# -

One thing I absolutely hate doing is reading xml, it bores me to bits. So to make this dreadful task a little more easier I use a nice little extension function that I found (and improved; then put up on stackoverflow). If you mark a class with the XmlSerialization attributes (XmlRoot/XmlElement) you can quickly take an xml string and turn it in to an object.

ASP.Net Pager Control -

I built this quite a while ago - some one might find it useful.

Feb 16

Find the transparent pixels in an image - WPF

The other day I had to create an image element that contained a png with transparent sections and have it display a hand cursor when the mouse was over the opaque sections.

The first thing I tried (and failed) was to have an image element with the cursor property set to “Hand” like so:

<Image Source=”{Binding SomeImage}” Cursor=”Hand” />

That obviously never worked so I was forced to look at each individual pixel and see if it was transparent. What I ended up with was a function that generated a bunch of coordinates.

This is that function:

private static Dictionary<Point, object> FindTransparentPixelCoordinates(BitmapSource source)
{
  var points = new Dictionary<Point, object>();

  // Convert the source if the pixel format is not what we expect
  if (source.Format != PixelFormats.Bgra32)
  {
    source = new FormatConvertedBitmap(source, PixelFormats.Bgra32, null, 0);
  }

  int width = source.PixelWidth;
  int height = source.PixelHeight;
  var bytes = new byte[width * height * 4];

  source.CopyPixels(bytes, width * 4, 0);

  var position = 0;

  for (var y = 0; y < height; y++)
  {
    for (var x = 0; x < width; x++)
    {
      var byteOffset = position;

      // The pixel format is stored as 32-bits (4 bytes) with the last byte being the alpha

      if (bytes[byteOffset + 3] == 0)
      {
        points.Add(new Point(x, y), null);
      }

      position += 4;
    }
  }

  return points;
}

Jan 28

The Morning Brew -

Fantastic site that keeps me updated on all the goings on around .Net / Development.

Jan 25

Chimp TV -

The chimps chose a good score to accompany their film ;)

Jan 24

WPF 4 & Touch -

Invaluable resource for getting start with touch and WPF 4. Helped out greatly when developing the touch features of the graphic.ly WPF app.

Jan 19

[video]

Jan 10

Day 0

Until I can think of something to write for this I’ll start off by telling you all little about my self. In bullet form of course ;)

That’s it for now…

Cheerio

P.S.

I’m also online else where:

Twitter

Facebook

LinkedIn

StackOverFlow