JQuery插件上传头像
2013-05-08 21:01
429 查看
protected void Page_Load(object sender, EventArgs e)
{
int intBigHeight;
int intBigWidth;
string strBigData;
int intSmallHeight;
int intSmallWidth;
string strSmallData;
try
{
intBigHeight = int.Parse(Request.Form["BigHeight"].ToString());
intBigWidth = int.Parse(Request.Form["BigWidth"].ToString());
strBigData = Request.Form["BigData"].ToString();
string bigimgurl = "upload/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "icon.jpg";
SaveBmp(BuildBitmap(intBigWidth, intBigHeight, strBigData), Server.MapPath(bigimgurl));
intSmallHeight = int.Parse(Request.Form["SmallHeight"].ToString());
intSmallWidth = int.Parse(Request.Form["SmallWidth"].ToString());
strSmallData = Request.Form["SmallData"].ToString();
string smallimgurl = "upload/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "icon_s.jpg";
SaveBmp(BuildBitmap(intSmallWidth, intSmallHeight, strSmallData), Server.MapPath(smallimgurl));
if (store(bigimgurl, smallimgurl) > 0)//验证是否上传到数据库
{
Response.Write("1");
}
else
{
Response.Write("0");
}
}
catch
{
Response.Write("0");
}
}
public int store(string bigimgurl, string smallimgurl)//上传到数据库方法
{
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "insert into T_imgurl(bigimg,smallimg) values(@bigimgurl,@smallimgurl)";
cmd.Parameters.AddWithValue("@bigimgurl", bigimgurl);
cmd.Parameters.AddWithValue("@smallimgurl", smallimgurl);
int num = cmd.ExecuteNonQuery();
return num;
cmd.Dispose();
conn.Dispose();
}
public System.Drawing.Bitmap BuildBitmap(int width, int height, string strBmp)
{
System.Drawing.Bitmap tmpBmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
string[] StmpBmp = strBmp.Split(',');
int pos = 0;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
tmpBmp.SetPixel(x, y, Color.FromArgb(int.Parse(StmpBmp[pos], System.Globalization.NumberStyles.HexNumber)));
pos++;
}
}
return tmpBmp;
}
{
int intBigHeight;
int intBigWidth;
string strBigData;
int intSmallHeight;
int intSmallWidth;
string strSmallData;
try
{
intBigHeight = int.Parse(Request.Form["BigHeight"].ToString());
intBigWidth = int.Parse(Request.Form["BigWidth"].ToString());
strBigData = Request.Form["BigData"].ToString();
string bigimgurl = "upload/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "icon.jpg";
SaveBmp(BuildBitmap(intBigWidth, intBigHeight, strBigData), Server.MapPath(bigimgurl));
intSmallHeight = int.Parse(Request.Form["SmallHeight"].ToString());
intSmallWidth = int.Parse(Request.Form["SmallWidth"].ToString());
strSmallData = Request.Form["SmallData"].ToString();
string smallimgurl = "upload/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "icon_s.jpg";
SaveBmp(BuildBitmap(intSmallWidth, intSmallHeight, strSmallData), Server.MapPath(smallimgurl));
if (store(bigimgurl, smallimgurl) > 0)//验证是否上传到数据库
{
Response.Write("1");
}
else
{
Response.Write("0");
}
}
catch
{
Response.Write("0");
}
}
public int store(string bigimgurl, string smallimgurl)//上传到数据库方法
{
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "insert into T_imgurl(bigimg,smallimg) values(@bigimgurl,@smallimgurl)";
cmd.Parameters.AddWithValue("@bigimgurl", bigimgurl);
cmd.Parameters.AddWithValue("@smallimgurl", smallimgurl);
int num = cmd.ExecuteNonQuery();
return num;
cmd.Dispose();
conn.Dispose();
}
public System.Drawing.Bitmap BuildBitmap(int width, int height, string strBmp)
{
System.Drawing.Bitmap tmpBmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
string[] StmpBmp = strBmp.Split(',');
int pos = 0;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
tmpBmp.SetPixel(x, y, Color.FromArgb(int.Parse(StmpBmp[pos], System.Globalization.NumberStyles.HexNumber)));
pos++;
}
}
return tmpBmp;
}
相关文章推荐
- ASP 实例:头像上传。文件(图片)上传,头像截取(Jquery的imgAreaSelect插件来选取截取区域)
- ASP 实例:头像上传。文件(图片)上传,头像截取(Jquery-ui插件来选取截取区域)
- jQuery 自制上传头像插件-附带Demo实例(ajaxfileupload.js第三弹)
- jQuery 上传头像插件Jcrop的实例
- jQuery 自制上传头像插件-附带Demo实例(ajaxfileupload.js第三弹) 推荐
- 头像上传插件(php+jquery_jcrop_js+jquery_form_js实现)
- 【jQuery插件】使用cropper实现简单的头像裁剪并上传
- 简单测试实现 博客园的头像上传功能 使用插件jquery jcrop+fineupload
- 使用jquery的imagecropper插件做用户头像上传 兼容移动端
- JQuery-Jcrop插件裁剪头像,及头像的上传
- jQuery上传插件,文件上传测试用例
- [转载]jQuery上传插件Uploadify使用详解
- 【.Net码农】JQuery上传插件Uploadify使用详解
- 基于jquery的上传插件Uploadify 3.1.1在MVC3中的使用
- 强大的支持多文件上传的jQuery文件上传插件Uploadify
- jquery.uploadify上传插件security error 解决
- JQuery上传插件Uploadify使用详解
- jQuery插件uploadify实现ajax效果的图片上传
- uploadify(jquery)插件的使用及图片上传预览
- 利用Jquery的cropper插件实现拖动层动态头剪切(裁剪头像)图片