特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> ASP.NET教程> 封装的一些实现图片水印与图片自动结合缩放的类

封装的一些实现图片水印与图片自动结合缩放的类

时间:2009-07-01 16:27:04 作者:互联网

  1using System;
  2using Sy***m.Data;
  3using Sy***m.Configuration;
  4using Sy***m.Web;
  5using Sy***m.Web.Security;
  6using Sy***m.Web.UI;
  7using Sy***m.Web.UI.WebControls;
  8using Sy***m.Web.UI.WebControls.WebParts;
  9using Sy***m.Web.UI.HtmlControls;
 10using Sy***m.Drawing;
 11namespace WebHelper
 12{
 13
 14    /**////


 15    /// ImageHelper 的摘要说明
 16    ///

 17    public class ImageHelper
 18    {
 19        public ImageHelper()
 20        {
 21            //
 22            // TODO: 在此处添加构造函数逻辑
 23            //
 24        }
 25        Image水印#region Image水印
 26        /**////
 27        /// 写入图像水印
 28        ///

 29        /// 水印字符串
 30        /// 原图片位置
 31        /// 水印加入后的位置
 32        ///
 33        public  string CreateBackImage(Sy***m.Web.UI.Page pageCurrent, string str, string filePath, string savePath, int x, int y)
 34        {
 35            Sy***m.Drawing.Image img = Sy***m.Drawing.Image.FromFile(pa***urrent.MapPath(filePath));
 36            //创建图片
 37            Graphics graphics = Gr***ics.FromImage(img);
 38            //指定要绘制的面积
 39            gr***ics.DrawImage(img, 0, 0, im***idth, im***eight);
 40            //定义字段和画笔
 41            Font font = new Font("黑体", 16);
 42            Brush brush = new SolidBrush(Co***.Yellow);
 43            gr***ics.DrawString(str, font, brush, x, y);
 44            //保存并输出图片
 45            img.Save(pa***urrent.MapPath(savePath), Sy***m.Drawing.Imaging.ImageFormat.Jpeg);
 46            return savePath;
 47
 48        }
 49        #endregion
 50        Image自动缩小#region Image自动缩小
 51        /**////
 52        /// 缩小图片到指定的大小
 53        ///

 54        ///
 55        /// 原图片的位置
 56        ///
 57        ///
 58        /// 缩小后的图片位置
 59        ///
 60        ///
 61        /// 宽度
 62        ///
 63        ///
 64        /// 高度
 65        ///
 66        public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
 67        {
 68
 69            Sy***m.Drawing.Bitmap objPic, objNewPic;
 70            try
 71            {
 72                objPic = new Sy***m.Drawing.Bitmap(strOldPic);
 73                objNewPic = new Sy***m.Drawing.Bitmap(objPic, intWidth, intHeight);
 74                ob***wPic.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            Sy***m.Drawing.Bitmap objPic, objNewPic;
 89            try
 90            {
 91                objPic = new Sy***m.Drawing.Bitmap(strOldPic);
 92                int intHeight = Co***rt.ToInt32(((intWidth * 1.0) / (ob***c.Width * 1.0)) * ob***c.Height);
 93                objNewPic = new Sy***m.Drawing.Bitmap(objPic, intWidth, intHeight);
 94                ob***wPic.Save(strNewPic, ob***c.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        //    Sy***m.Drawing.Bitmap objPic, objNewPic;
109        //    try
110        //    {
111        //        objPic = new Sy***m.Drawing.Bitmap(strOldPic);
112        //        int intWidth = Co***rt.ToInt32(((intHeight * 1.0) / ob***c.Height) * ob***c.Width);
113        //        objNewPic = new Sy***m.Drawing.Bitmap(objPic, intWidth, intHeight);
114        //        ob***wPic.Save(strNewPic, ob***c.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.cnblogs.com/chu888chu888/archive/2007/01/09/615803.html

相关文章 最新文章

相关应用

热门文章

猜你喜欢

返回顶部