Click here to Skip to main content
6,595,854 members and growing! (17,821 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

Export JPEG with Flash/ASP.NET

By besterh

How to export an jpeg image from Flash using ASP.NET
C# 2.0, Windows, .NET 2.0, ASP.NET, Visual Studio, WebForms, Dev
Posted:28 Nov 2007
Views:19,365
Bookmarked:15 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
2 votes for this article.
Popularity: 0.96 Rating: 3.20 out of 5

1

2
1 vote, 50.0%
3
1 vote, 50.0%
4

5

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


Member

Occupation: Architect
Company: UCS Software Manufacturing
Location: South Africa South Africa

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralGreat Article Pinmembermaspevig13:29 17 Mar '09  
GeneralRe: Great Article Pinmemberbesterh20:42 17 Mar '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Nov 2007
Editor:
Copyright 2007 by besterh
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project