首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

辞职两个月,网站终于上线,最后一点有关问题请问

2013-03-26 
辞职两个月,网站终于上线,最后一点问题请教 public static string UploadImage(HttpPostedFileBase Upload

辞职两个月,网站终于上线,最后一点问题请教
 public static string UploadImage(HttpPostedFileBase UploadFile, int userid, int tWidth = 400, int tHeight = 400, string path = "/content/userhead/")
        {
            string result = "";
            System.IO.Stream oStream = null;
            System.Drawing.Image oImage = null;
            using (oStream = UploadFile.InputStream)
            {
                using (System.Drawing.Image img11 = System.Drawing.Image.FromStream(oStream))
                {
                    oImage = new System.Drawing.Bitmap(img11);
                    img11.Dispose();
                    oStream.Dispose();

                    int oWidth = oImage.Width;
                    int oHeight = oImage.Height;
                    if (oWidth < tWidth && oHeight < tHeight)
                    {
                        return result;
                    }
                    if (oWidth >= oHeight)
                        tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth) / Convert.ToDouble(oWidth)));
                    else
                        tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight) / Convert.ToDouble(oHeight)));

                    Bitmap tImage = new Bitmap(tWidth, tHeight);//70x70
                    using (Graphics g = Graphics.FromImage(tImage))
                    {


                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量插值法 
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;//设置高质量,低速度呈现平滑程度 
                        g.Clear(Color.Transparent); //清空画布并以透明背景色填充 
                        g.DrawImage(oImage, new Rectangle(0, 0, tWidth, tHeight), new Rectangle(0, 0, oWidth, oHeight), GraphicsUnit.Pixel);

                        string file = userid + ".jpg";
                        string oFullName = System.Web.HttpContext.Current.Server.MapPath(path) + file;//保存小图的物理路径 
                        result = file;
                        try
                        {
                            oImage.Dispose();
                            oStream.Dispose();
                            g.Dispose();
                            tImage.Save(oFullName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            oImage.Dispose();


                            oStream.Dispose();
                            g.Dispose();
                            tImage.Dispose();
                        }
                        return path + result;
                    }
                }
            }

网站有个功能上传图片并压缩的,用这段代码又会有问题,多上传几次就会提示图片被锁定无法操作,有人知道怎么解决吗?

另外希望大家对我的网站发展给点的建议,www.84qy.net
[解决办法]
并发?图片正在使用中?
[解决办法]
int userid此参数不知传进来的是何值,假如为一固定值则:string file = userid + ".jpg";此句则产生文件名相同。多次上传会出现错误情况。

热点排行