⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makepic.aspx.cs

📁 flash cs3 在线视频拍照
💻 CS
字号:
/*   Author :潇笑 blog: http://xiaoxiao.bfor.cn
 * 
 * 
 * 
 * */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using Spaces;
using System.Drawing.Imaging;
using System.IO;
using System.Text;

public partial class Admin_MakePic : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        //flash post出来的数据,有width,height
        string account = User.Identity.Name;
        if (account == string.Empty)
        {
            return;
        }
        int width = 0;
        int height = 0;

        if (!int.TryParse(Request.Form["width"], out width) &&
         !int.TryParse(Request.Form["height"], out  height))
        { 
            throw new ApplicationException("照片格式不正确!");
        }
        //测试post来的数据
        //Response.Write(Request.Form);
        //Response.End();
        //定义bitmap ,宽,高,和格式
         Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
         Rectangle rect = new Rectangle(0, 0, width, height);
         //本来用的方案 copy bit数组
       //  System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
       //  IntPtr iPtr = bmpData.Scan0;
       //    int iStride = bmpData.Stride;

         int iBytes = width * height * 3;//宽*长 *3是因为每一点都需要rgb三种色值填充
         byte[] PixelValues = new byte[iBytes];

         int iPoint = 0;

         bmp.MakeTransparent(Color.White);
         for (int i = 0; i < height; i++)//填充每一行的色值
         {
             string[] ss=Request.Form["px"+i].Split(','); //解析行数据分组
             for (int j = 0; j < width; j++)
             {
                 string values = ss[j];
                 while (values.Length < 6)
                 {
                     values = "0" + values; //位不足填充
                 }
                 string s1, s2, s3;//获取RGB
                 s1 = values.Substring(0, 2);
                 s2 = values.Substring(2, 2);
                 s3 = values.Substring(4, 2);
                // int iGray = Gray[i, j];
                // int gr = Convert.ToInt32(ss[j],16);
               //  PixelValues[iPoint] = PixelValues[iPoint + 1] = PixelValues[iPoint + 2] = Convert.ToByte(gr);
                 PixelValues[iPoint] = Convert.ToByte(Convert.ToInt32(s1,16));
                 PixelValues[iPoint+1] = Convert.ToByte(Convert.ToInt32(s2, 16));
                 PixelValues[iPoint+2] = Convert.ToByte(Convert.ToInt32(s3, 16));
                 //设置点陈color
                  bmp.SetPixel(j, i, Color.FromArgb(PixelValues[iPoint], PixelValues[iPoint + 1], PixelValues[iPoint + 2]));
                 
                 iPoint += 3;
               //  Response.Write(gr+"<br/>");
             }
         }


        // System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);

        // bmp.UnlockBits(bmpData);
         //注意,目录一下要有权限,至少要有User和户修改权限
         string path=@"d:\test\"+DateTime.Now.ToFileTime()+".jpg";
         bmp.Save(path, ImageFormat.Jpeg);
       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -