网上大多是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,这就是主要的处理流程
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源码