隨筆-3  評(píng)論-26  文章-41  trackbacks-0

          public void MakeSmallImg(string FromImg,string SaveImg,System.Double Width,System.Double Height) {
           /*
           System.Drawing.Image Image=System.Drawing.Image.FromFile(FromImg);
           */
           //原始圖片名稱(chēng)
           string originalFilename =FromImg;
           //生成的高質(zhì)量圖片名稱(chēng)
           string strGoodFile =SaveImg;

           //從文件取得圖片對(duì)象
           System.Drawing.Image image = System.Drawing.Image.FromFile(originalFilename);
           System.Double NewWidth,NewHeight;
           if(image.Width>image.Height) {
            NewWidth=Width;
            NewHeight=image.Height*(NewWidth/image.Width);
           } else {
            NewHeight=Height;
            NewWidth=(NewHeight/image.Height)*image.Width;
           }

           if (NewWidth>Width) {
            NewWidth=Width;
           }
           if (NewHeight>Height) {
            NewHeight=Height;
           }

           //取得圖片大小
           System.Drawing.Size size = new Size(int.Parse(ClDot(NewWidth.ToString())),int.Parse(ClDot(NewHeight.ToString())));
           //新建一個(gè)bmp圖片
           System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width,size.Height);
           //新建一個(gè)畫(huà)板
           System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
           //設(shè)置高質(zhì)量插值法
           g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
           //設(shè)置高質(zhì)量,低速度呈現(xiàn)平滑程度
           g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
           //清空一下畫(huà)布
           g.Clear(Color.Blue);
           //在指定位置畫(huà)圖
           g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
           new System.Drawing.Rectangle(0, 0, image.Width,image.Height),
           System.Drawing.GraphicsUnit.Pixel);

           ///文字水印
           System.Drawing.Graphics G=System.Drawing.Graphics.FromImage(bitmap);
           System.Drawing.Font f=new Font("宋體",10);
           System.Drawing.Brush b=new SolidBrush(Color.Black);
           G.DrawString(MarkText,f,b,10,10);
           G.Dispose();

           ///圖片水印
           System.Drawing.Image copyImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(MarkLogo));
           Graphics a = Graphics.FromImage(bitmap);
           a.DrawImage(copyImage, new Rectangle(bitmap.Width-copyImage.Width,bitmap.Height-copyImage.Height,copyImage.Width, copyImage.Height),0,0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);

           copyImage.Dispose();
           a.Dispose();
           copyImage.Dispose();

           //保存高清晰度的縮略圖
           bitmap.Save(strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg);

           g.Dispose();
           image.Dispose();
          }

          source:http://feisha.cn/Articles/Art.162.htm
          posted on 2008-04-17 09:38 百年 閱讀(777) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): .net
          主站蜘蛛池模板: 平山县| 泸西县| 滦平县| 六枝特区| 拜城县| 九龙城区| 苗栗县| 张家界市| 监利县| 丰镇市| 长沙县| 郧西县| 鹰潭市| 山东省| 龙口市| 云霄县| 左权县| 晋城| 平罗县| 喀什市| 钦州市| 长汀县| 磐石市| 双江| 轮台县| 涪陵区| 浙江省| 东海县| 盐山县| 临桂县| 哈尔滨市| 江城| 白玉县| 建平县| 阳东县| 凤翔县| 阿鲁科尔沁旗| 东丰县| 永宁县| 托克逊县| 南平市|