当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  封装的一些实现图片水印与图片自动结合缩放的类

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

点击次数:22 次 发布日期:2008-11-26 11:35: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 /
源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华