Click here to Skip to main content
Licence 
First Posted 28 Nov 2007
Views 27,901
Bookmarked 20 times

Export JPEG with Flash/ASP.NET

By | 28 Nov 2007 | Article
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.

        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

About the Author

besterh

Architect
UCS Software Manufacturing
South Africa South Africa

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGreat Article Pinmembermaspevig12:29 17 Mar '09  
GeneralRe: Great Article Pinmemberbesterh19:42 17 Mar '09  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 29 Nov 2007
Article Copyright 2007 by besterh
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid