<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

     public string GetSqlFile(FileUpload fp, int width, int height)
            {
                string sqlfile = "";
                string tempSqlPath = "";
                string path = HttpContext.Current.Request.PhysicalApplicationPath.ToString() + "upload/";
                path += "UploadFile/" + DateTime.Now.ToString("yyyyMM");
                tempSqlPath = "\\upload\\UploadFile\\" + DateTime.Now.ToString("yyyyMM");
                if (Directory.Exists(path))
                {

                }
                else
                {
                    Directory.CreateDirectory(path);
                }
                if (Directory.Exists(path + "/small"))
                {
                }
                else
                {
                    Directory.CreateDirectory(path + "/small");
                }
                if (Directory.Exists(path + "/temp"))
                {
                }
                else
                {
                    Directory.CreateDirectory(path + "/temp");
                }
                //HttpFileCollection files = HttpContext.Current.Request.Files;

                if (fp.FileName.ToString().Length > 0)
                {
                    string filename = fp.FileName.ToString();
                    string datestr = DateTime.Now.ToString("yyyyMMddHmmssfff");
                    string ext = filename.Substring(filename.LastIndexOf(".")).ToLower();
                    if (ext != ".bmp" && ext != ".jpg" && ext != ".gif" && ext != ".jpeg")
                    {
                        HttpContext.Current.Response.Write("<script>alert('上傳的文件不是.gif,jpg,jpeg,bmp格式')</script>");
                        return "";
                    }
                    string tempFilePath = path + "/" + "temp/" + datestr + ext;
                    fp.SaveAs(tempFilePath);
                    #region 生成小圖
                    string originalFilename = path + "/" + datestr + ext;
                   //fp.FileBytes
                    //縮小的倍數
                    int iScale = 1;
                    //從文件取得圖片對象
                    System.Drawing.Image image = null;
                    try
                    {
                        image = System.Drawing.Image.FromFile(tempFilePath);
                       
                    }
                    catch
                    {
                        //
                        try
                        {
                            File.Delete(tempFilePath);
                            image.Dispose();

                        }
                        catch
                        {
                        }
                        HttpContext.Current.Response.Write("<script>alert('上傳的文件不是.gif,jpg,jpeg,bmp圖片的標準格式格式')</script>");
                        return "";

                    }
                    int hi = 0;
                    int wi = 0;
                    wi = width;
                    hi = height;
                    Size size = new Size(wi, hi);
                    //新建一個bmp圖片
                    System.Drawing.Image bitmap = new Bitmap(size.Width, size.Height);
                    //新建一個畫板
                    Graphics g = Graphics.FromImage(bitmap);
                    //設置高質量插值法
                    g.InterpolationMode = InterpolationMode.High;
                    //設置高質量,低速度呈現平滑程度
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    //清空一下畫布
                    g.Clear(Color.Blue);
                    //在指定位置畫圖
                    g.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                    if (ext == ".jpg" || ext == ".jpeg")
                        bitmap.Save(path + "/small/" + datestr + ext, ImageFormat.Jpeg);
                    if (ext == ".gif")
                        bitmap.Save(path + "/small/" + datestr + ext, ImageFormat.Gif);
                    if (ext == ".bmp")
                        bitmap.Save(path + "/small/" + datestr + ext, ImageFormat.Bmp);
                    ///大圖片
                    if (fp.FileBytes.Length > 300000){
                      //image.Width
                       // image.Height


                        wi = 800;

                        hi = Convert.ToInt32(image.Height * (Convert.ToDouble(wi) / Convert.ToDouble(image.Width)));                
                         size = new Size(wi, hi);
                        //新建一個bmp圖片
                      bitmap = new Bitmap(size.Width, size.Height);
                        //新建一個畫板
                        g = Graphics.FromImage(bitmap);
                        //設置高質量插值法
                        g.InterpolationMode = InterpolationMode.High;
                        //設置高質量,低速度呈現平滑程度
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        //清空一下畫布
                        g.Clear(Color.Blue);
                        //在指定位置畫圖
                        g.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                        if (ext == ".jpg" || ext == ".jpeg")
                            bitmap.Save(originalFilename, ImageFormat.Jpeg);
                        if (ext == ".gif")
                            bitmap.Save(originalFilename, ImageFormat.Gif);
                        if (ext == ".bmp")
                            bitmap.Save(originalFilename, ImageFormat.Bmp);

                    }
                    else {
                        fp.SaveAs(originalFilename);
                    }
                    image.Dispose();
                    bitmap.Dispose();
                    g.Dispose();
                    #endregion
                    sqlfile = datestr + ext;

                    try
                    {
                        image.Dispose();
                        bitmap.Dispose();
                        g.Dispose();
                        File.Delete(tempFilePath);
                    }
                    catch (Exception ex)
                    {
                        string exc = ex.Message.ToString();
                        HttpContext.Current.Response.Write("<script>alert('" + exc + "');</script>");
                    }
                }
                else
                {
                    sqlfile = "";
                }
                sqlfile = sqlfile.Length>0?(tempSqlPath + "\\" + sqlfile):("");
                return sqlfile;
            }

    posted on 2009-04-01 18:02 sanmao 閱讀(415) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    常用鏈接

    留言簿(5)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 毛片在线看免费版| 84pao国产成视频免费播放| 免费a级毛片大学生免费观看| 91亚洲国产成人久久精品网站 | 免费无码看av的网站| 亚洲一区在线免费观看| 久久受www免费人成_看片中文| 亚洲美女视频网址| 国产免费一区二区三区| 亚洲免费视频网址| 免费被黄网站在观看| 美女免费视频一区二区| 亚洲?V乱码久久精品蜜桃| 边摸边吃奶边做爽免费视频网站| 免费在线精品视频| 中国在线观看免费的www| 亚洲福利视频一区| 99亚洲精品卡2卡三卡4卡2卡| 国产大片91精品免费看3| 无码日韩人妻AV一区免费l| 亚洲理论电影在线观看| 久久精品国产亚洲αv忘忧草| 成人免费视频观看无遮挡| 特级毛片aaaa级毛片免费| 亚洲无线观看国产精品| 无码精品人妻一区二区三区免费看 | 国产福利免费在线观看| a高清免费毛片久久| 亚洲激情中文字幕| 在线A级毛片无码免费真人| 亚洲一级片免费看| 亚洲成AV人片久久| jjzz亚洲亚洲女人| 84pao国产成视频免费播放| 国产亚洲精品成人久久网站| 亚洲国产美女精品久久久久∴| 国产精品视频免费| www成人免费视频| 亚洲一区二区影视| 中文字幕亚洲无线码a| 国国内清清草原免费视频99|