网络软件 系统工具 应用软件 图形图像 多媒体类 免费游戏 安全相关 免费音乐 网页素材 电子书籍 考试考题 建站源码
教育教学 多媒体类 编程开发 操作系统 游戏天地 娱乐天地 简历求职 站长专区 网页设计 安全技术 图形图像 文学驿站
业界资讯 | 图形图像 | 操作系统 | 网络冲浪 | 工具软件 | 办公软件 | 媒体动画 | 精文荟萃 | 认证考试 | 网页设计 | 技术开发 | 专栏
当前位置:热点网络学院技术开发.Net 专栏.NET使用封装的一些实现图片水印与图片自动结合缩放的类
精品推荐
热点TOP10
·ASP.Net实现将Word转换PDF格式
·ASP.NET IIS 注册工具 (Aspnet_regiis.exe)
·安装ASP.NET完全手册
·ASP.Net+XML打造留言薄
·Asp.Net中使用水晶报表
·asp.net结合html,javascript实现无刷新跨域数据提交
·Autodesk官方最新的.NET教程(一)(C#版)
·ASP.NET中为DataGrid添加单选框
·一个ASP.NET的进度条
·用Asp.Net创建基于Ajax的聊天室程序
·在ASP.net中保存/取出图片入/从SQL数据库(可用于上传图片)
·解决ASP.NET的进程帐户没有访问 IIS的权限
·VB.Net基本语句
·Asp.net cache 简述
·Web应用程序ASP.NET开发电子商务网站购物车
·关于ASP.NET在IIS一些问题的经验总结
·跳出封装剖析ASP.NET脚本回调的原理
·一个高效判断字符串是否全数字的函数
·在ASP.NET应用中插入flash动画
·ASP.NET 拒绝访问
封装的一些实现图片水印与图片自动结合缩放的类
日期:2007年1月13日 作者: 查看:[大字体 中字体 小字体]

  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: 在此处添加构造函数逻辑
 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            //创建图片
 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自动缩小#region Image自动缩小
 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.xmsc.com.cn)

关于我们 | 帮助(?) | 版权声明 | 友情连接 
Copyright 2005-2005 xmsc.com.cn All Rights Reserved.
Powered by:mesky