国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

封裝的一些實(shí)現(xiàn)圖片水印與圖片自動(dòng)結(jié)合縮放的類

2019-11-18 16:44:51
字體:
供稿:網(wǎng)友

  1using System;
  2using System.Data;
  3using System.Configuration;
  4using System.Web;
  5using System.Web.Security;
  6using System.Web.UI;
  7using System.Web.UI.WebControls;
  8using System.Web.UI.WebControls.WebParts;
  9using System.Web.UI.HtmlControls;
 10using System.Drawing;
 11namespace WebHelper
 12{
 13
 14    /**//// <summary>
 15    /// ImageHelper 的摘要說明
 16    /// </summary>
 17    public class ImageHelper
 18    {
 19        public ImageHelper()
 20        {
 21            //
 22            // TODO: 在此處添加構(gòu)造函數(shù)邏輯
 23            //
 24        }
 25        Image水印#region Image水印
 26        /**//// <summary>
 27        /// 寫入圖像水印
 28        /// </summary>
 29        /// <param name="str">水印字符串</param>
 30        /// <param name="filePath">原圖片位置</param>
 31        /// <param name="savePath">水印加入后的位置</param>
 32        /// <returns></returns>
 33        public  string CreateBackImage(System.Web.UI.Page pageCurrent, string str, string filePath, string savePath, int x, int y)
 34        {
 35            System.Drawing.Image img = System.Drawing.Image.FromFile(pageCurrent.MapPath(filePath));
 36            //創(chuàng)建圖片
 37            Graphics graphics = Graphics.FromImage(img);
 38            //指定要繪制的面積
 39            graphics.DrawImage(img, 0, 0, img.Width, img.Height);
 40            //定義字段和畫筆
 41            Font font = new Font("黑體", 16);
 42            Brush brush = new SolidBrush(Color.Yellow);
 43            graphics.DrawString(str, font, brush, x, y);
 44            //保存并輸出圖片
 45            img.Save(pageCurrent.MapPath(savePath), System.Drawing.Imaging.ImageFormat.Jpeg);
 46            return savePath;
 47
 48        }
 49        #endregion
 50        Image自動(dòng)縮小#region Image自動(dòng)縮小
 51        /**//// <summary>
 52        /// 縮小圖片到指定的大小
 53        /// </summary>
 54        /// <param name="strOldPic">
 55        /// 原圖片的位置
 56        /// </param>
 57        /// <param name="strNewPic">
 58        /// 縮小后的圖片位置
 59        /// </param>
 60        /// <param name="intWidth">
 61        /// 寬度
 62        /// </param>
 63        /// <param name="intHeight">
 64        /// 高度
 65        /// </param>
 66        public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
 67        {
 68
 69            System.Drawing.Bitmap objPic, objNewPic;
 70            try
 71            {
 72                objPic = new System.Drawing.Bitmap(strOldPic);
 73                objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
 74                objNewPic.Save(strNewPic);
 75
 76            }
 77            catch (Exception exp) { throw exp; }
 78            finally
 79            {
 80                objPic = null;
 81                objNewPic = null;
 82            }
 83        }
 84
 85        public void SmallPic(string strOldPic, string strNewPic, int intWidth)
 86        {
 87
 88            System.Drawing.Bitmap objPic, objNewPic;
 89            try
 90            {
 91                objPic = new System.Drawing.Bitmap(strOldPic);
 92                int intHeight = Convert.ToInt32(((intWidth * 1.0) / (objPic.Width * 1.0)) * objPic.Height);
 93                objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
 94                objNewPic.Save(strNewPic, objPic.RawFormat);
 95
 96            }
 97            catch (Exception exp) { throw exp; }
 98            finally
 99            {
100                objPic = null;
101                objNewPic = null;
102            }
103        }
104
105        //public void SmallPic(string strOldPic, string strNewPic, int intHeight)
106        //{
107
108        //    System.Drawing.Bitmap objPic, objNewPic;
109        //    try
110        //    {
111        //        objPic = new System.Drawing.Bitmap(strOldPic);
112        //        int intWidth = Convert.ToInt32(((intHeight * 1.0) / objPic.Height) * objPic.Width);
113        //        objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
114        //        objNewPic.Save(strNewPic, objPic.RawFormat);
115
116        //    }
117        //    catch (Exception exp) { throw exp; }
118        //    finally
119        //    {
120        //        objPic = null;
121        //        objNewPic = null;
122        //    }
123        //}
124        #endregion
125
126    }
127}

http://www.survivalescaperooms.com/chu888chu888/archive/2007/01/09/615803.html


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 财经| 海晏县| 桂东县| 仙游县| 子洲县| 额敏县| 北辰区| 呼图壁县| 聂拉木县| 阿克| 孙吴县| 临漳县| 松桃| 江都市| 静宁县| 宁武县| 达州市| 淮南市| 宿州市| 涟源市| 天峨县| 互助| 岗巴县| 屏东市| 方山县| 老河口市| 鄢陵县| 林周县| 新化县| 武邑县| 惠州市| 策勒县| 田东县| 宜黄县| 武隆县| 西吉县| 略阳县| 西吉县| 宁都县| 九江市| 贡山|