asp.net中拍大頭帖解決方案 (源碼)

來源:互聯網
上載者:User
網上大多是php的,既然沒人做,那我做一個分享了 。。。

流程..  flash 拍下照片後提交到指定的處理常式。
資料: width,height,  px+xxx
解析行列,填充每一個點陣資料。

//儲存flash 提交過來的寬高值.並驗定
        int width = 0;
        int height = 0;

        if (!int.TryParse(Request.Form["width"], out width) &&
         !int.TryParse(Request.Form["height"], out  height))
        { 
            throw new ApplicationException("照片格式不正確!");
        }

//定義bitmap ,寬,高,和格式
         Bitmap bmp = new Bitmap(width, height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

//寬*長 *3是因為每一點都需要rgb三種色值填充
         int iBytes = width * height * 3;
         byte[] PixelValues = new byte[iBytes];
//當前位置
         int iPoint = 0;

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

 //注意,目錄一下要有許可權,至少要有User和戶修改許可權
         string path=@"d:\test\"+DateTime.Now.ToFileTime()+".jpg";
         bmp.Save(path, ImageFormat.Jpeg);

//OK,這就是主要的處理流程

 壓縮包中附說明源碼,和flash源碼

http://www.bfor.cn/download/MakePic.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.