export.aspx.cs
上传用户:ntgydz
上传日期:2022-07-17
资源大小:261k
文件大小:3k
源码类别:

FlashMX/Flex源码

开发平台:

Flash/ActionScript

  1. using System;
  2. using System.Web;
  3. using System.Drawing;
  4. using System.Drawing.Imaging;
  5. public partial class _export : System.Web.UI.Page 
  6. {
  7.     protected void Page_Load(object sender, EventArgs e)
  8.     {
  9.         if (Request.Form["width"] != null && Request.Form["width"] != String.Empty)
  10.         {
  11.             // image dimensions
  12.             int width = Int32.Parse((Request.Form["width"].IndexOf('.') != -1) ? Request.Form["width"].Substring(0, Request.Form["width"].IndexOf('.')) : Request.Form["width"]);
  13.             int height = Int32.Parse((Request.Form["height"].IndexOf('.') != -1) ? Request.Form["height"].Substring(0, Request.Form["height"].IndexOf('.')) : Request.Form["height"]);
  14.             // image
  15.             Bitmap result = new Bitmap(width, height);
  16.             // set pixel colors
  17.             for (int y = 0; y < height; y++)
  18.             {
  19.                 // column counter for the row
  20.                 int x = 0;
  21.                 // get current row data
  22.                 string[] row = Request.Form["r" + y].Split(new char[] { ',' });
  23.                 // set pixels in the row
  24.                 for (int c = 0; c < row.Length; c++)
  25.                 {
  26.                     // get pixel color and repeat count
  27.                     string[] pixel = row[c].Split(new char[] { ':' });
  28.                     Color current_color = ColorTranslator.FromHtml("#" + pixel[0]);
  29.                     int repeat = pixel.Length > 1 ? Int32.Parse(pixel[1]) : 1;
  30.                     // set pixel(s)
  31.                     for (int l = 0; l < repeat; l++)
  32.                     {
  33.                         result.SetPixel(x, y, current_color);
  34.                         x++;
  35.                     }
  36.                 }
  37.             }
  38.             // output image
  39.             // image type
  40.             Response.ContentType = "image/jpeg";
  41.             Response.AddHeader("Content-Disposition", "attachment; filename="amchart.jpg"");
  42.             // find image encoder for selected type
  43.             ImageCodecInfo[] encoders;
  44.             ImageCodecInfo img_encoder = null;
  45.             encoders = ImageCodecInfo.GetImageEncoders();
  46.             foreach (ImageCodecInfo codec in encoders)
  47.                 if (codec.MimeType == Response.ContentType)
  48.                 {
  49.                     img_encoder = codec;
  50.                     break;
  51.                 }
  52.             // image parameters
  53.             EncoderParameter jpeg_quality = new EncoderParameter(Encoder.Quality, 100L); // for jpeg images only
  54.             EncoderParameters enc_params = new EncoderParameters(1);
  55.             enc_params.Param[0] = jpeg_quality;
  56.             result.Save(Response.OutputStream, img_encoder, enc_params);
  57.         }
  58.         else
  59.         {
  60.             // invalid post
  61.             Response.Write("Invalid post");
  62.         }
  63.     }
  64. }