65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 Flash/ASP.NET 导出 JPEG

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.20/5 (2投票s)

2007 年 11 月 29 日

viewsIcon

38821

如何使用 ASP.NET 从 Flash 导出 JPEG 图像

引言

Flash 8 随附的新类“flash.display.BitmapData”使我们能够使用 Flash 和 PHP/ASP.NET 执行一些非常有趣的新操作。 我最近发现了一篇文章,演示了如何使用 BitmapData.gePixel() 方法导出 Flash 电影的屏幕截图并将其保存到服务器上。

与大多数 Flash 示例一样,对于 ASP.Net 开发人员来说几乎没有帮助,因为大多数示例都使用 PHP。 下面的代码是基于以下文章的扩展 http://www.sephiroth.it/tutorials/flashPHP/print_screen/index.php,基本上只是将他们的 PHP 代码翻译成 ASP.NET。

使用代码

如果您遵循该文章,那么下面的代码应该非常清楚。 我尽量保持格式和大部分代码相同,以便于比较。

        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();

希望这能帮助到某人。

历史

© . All rights reserved.