回复: asp.net拍大头帖的解决方案问题解决中。。。
MakePic.aspx.cs代码如下
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 System.Drawing.Imaging;
using System.IO;
using System.Text;
public partial class MakePic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int width = 0;
int height = 0;
int.TryParse(Request.Form["width"],out width);
int.TryParse(Request.Form["height"], out height);
Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Rectangle rect = new Rectangle(0, 0, width, height);
int iBytes = width * height * 3;
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;
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));
bmp.SetPixel(j, i, Color.FromArgb(PixelValues[iPoint], PixelValues[iPoint + 1], PixelValues[iPoint + 2]));
iPoint += 3;
}
}
string path = "img/" + DateTime.Now.ToFileTime() + ".JPG";
bmp.Save(Server.MapPath(path), ImageFormat.Jpeg);
Response.Write("拍照成功,保存于:" + path);
Response.Write("
");
}
}