您的位置:首页 > Web前端 > JQuery

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;

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: