Introduction
The new class that ships with Flash 8 "flash.display.BitmapData" allow us to do some pretty interesting new things using Flash and PHP/ASP.NET. I recently found and article that shows you how use the BitmapData.gePixel() method export a screenshot from a flash movie and save it to the server.
As with most Flash examples there is little of no help for ASP.Net developers, as most of the examples use PHP. The code below is extention off the following article http://www.sephiroth.it/tutorials/flashPHP/print_screen/index.php and is basically just a translation of their PHP code to ASP.NET.
Using the code
If you follow the article then the code below should be pretty clear. I tried to keep the format and most of the code the same to make it easier to compare.
int height = Convert.ToInt32(Request["height"]);
int width = Convert.ToInt32(Request["width"]);
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(new SolidBrush(Color.White), 0, 0, bmp.Width, bmp.Height);
for (int rows = 0; rows < height; rows++)
{
string[] row = Request["px" + rows].ToString().Split(",".ToCharArray());
for (int cols = 0; cols < width; cols++)
{
string value = row[cols];
if (value != "")
{
value = value.PadLeft(6, Convert.ToChar("0"));
int R = Convert.ToInt32(value.Substring(0, 2), 16);
int G = Convert.ToInt32(value.Substring(2, 2), 16);
int B = Convert.ToInt32(value.Substring(4, 2), 16);
System.Drawing.Color color = Color.FromArgb(R, G, B);
g.FillRegion(new SolidBrush(color), new Region(new Rectangle(cols, rows, 1, 1)));
}
}
}
bmp.Save(Server.MapPath("~/test.jpg"), ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
Hope this helps somebody.
History