ATTENTION ALL FANS!!! THIS BLOG HAS MOVED!!!
go to: http://www.taotekaching.com

Thursday, September 04, 2008

Flash RGB, C#, and Me...

Greetings,

So a co-worker of mine had to translate Flash RGB data into a Bitmap. He noted that finding that out was difficult, ergo, for your coding pleasure, here's a tasty little static function you can use just for that:




static Bitmap BmpOut(string rgb, int width, int height)
{
Bitmap bmp = null;
try
{
int bytes = (rgb.Length / (width * height));
bool IsArgb = (bytes == 8);
double dWidth = (double)width;
bmp = new Bitmap(width, height);
int counter = -1;
for (int i = 0; i < rgb.Length; i += bytes)
bmp.SetPixel(++counter % width, (int)Math.Floor((double)counter / dWidth),
Color.FromArgb(int.Parse(((!IsArgb) ? "FF" + rgb.Substring(i, 6) : rgb.Substring(i, 8)), System.Globalization.NumberStyles.HexNumber)));
}
catch { bmp = null; }
return bmp;
}


enjoy...

Submit this story to DotNetKicks