110,539
社区成员
发帖
与我相关
我的任务
分享
//flash post出来的数据,有width,height
int width = 0;
int height = 0;
if (!int.TryParse(Request.Form["width"], out width) &&
!int.TryParse(Request.Form["height"], out height))
{
throw new ApplicationException("照片格式不正确!");
}
width = int.Parse(Request.Form["width"]);
height = int.Parse(Request.Form["height"]);
//定义bitmap ,宽,高,和格式
Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Rectangle rect = new Rectangle(0, 0, width, height);
//宽*长 *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;
}
}
var camArray = Camera.names;
if (camArray.length == 0)
{
trace("没有摄像头");
}