網上大多是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