Click here to Skip to main content
15,896,557 members
Articles / Web Development / ASP.NET
Article

Export JPEG with Flash/ASP.NET

Rate me:
Please Sign up or sign in to vote.
3.20/5 (2 votes)
28 Nov 2007 38.5K   20   2
How to export an jpeg image from Flash using ASP.NET

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.

C#
int height = Convert.ToInt32(Request["height"]);
int width = Convert.ToInt32(Request["width"]);
// create the image with desired width and height
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
// now fill the image with blank color
// do you remember i wont pass the 0xFFFFFF pixels
// from flash?
g.FillRectangle(new SolidBrush(Color.White), 0, 0, bmp.Width, bmp.Height);
// now process every POST variable which
// contains a pixel color
for (int rows = 0; rows < height; rows++)
{
    // convert the string into an array of n elements
    string[] row = Request["px" + rows].ToString().Split(",".ToCharArray());
    for (int cols = 0; cols < width; cols++)
    {
        // get the single pixel color value
        string value = row[cols];
        // if value is not empty (empty values are the blank pixels)
        if (value != "")
        {
            // get the hexadecimal string (must be 6 chars length)
            // so add the missing chars if needed
            value = value.PadLeft(6, Convert.ToChar("0"));
            // Convert the hex code color string to a standard color class.
            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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect UCS Software Manufacturing
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat Article Pin
maspevig17-Mar-09 12:29
maspevig17-Mar-09 12:29 
GeneralRe: Great Article Pin
besterh17-Mar-09 19:42
besterh17-Mar-09 19:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.