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

2016-02-19 21:52 5 1 收藏

下面,图老师小编带您去了解一下封装的一些实现图片水印与图片自动结合缩放的类,生活就是不断的发现新事物,get新技能~

【 tulaoshi.com - Web开发 】

    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        /

来源:https://www.tulaoshi.com/n/20160219/1627343.html

延伸阅读
标签: Web开发
% '函数功能:远程图片自动保存到本地服务器,并利用aspjpeg为图片加上水印 '(注意:请先在目录下创建images目录,用来保存临时图片) '本程序需要在服务器上安装"aspjpeg组件"否则无法正常使用 '也可以只取'''''22222222'''''''以上的部分,这部分可以保存图片,第二部分是进行水印增加 '使用方法,请保存为saveimg.asp 'saveimg.asp?url=h...
以前在eoe论坛中找过裁剪图片为圆形图片的方法,但是效果都不是很理想,这几天因为公司业务的要求,需要对头像进行裁剪以圆形的方式显示,这个方法是根据传入的图片的高度(height)和宽度(width)决定的,如果是 width = height时,则会裁剪高度,裁剪的区域是宽度不变高度从顶部到宽度width的长度;如果 width height,则会裁剪宽度,裁剪的...
图片水印怎么去掉 PS最快图片水印去掉方法   图片水印怎么去掉这是我们在工作和生活中经常遇见的一个问题,往往一张很好的图片下载下来却发现上面有不想要的水印,网络上关于如何图片水印去掉的方法很多,但是很多都很复杂,这里介绍一种最快的图片水印去除方法,注意这里需要利用PS软件,如果没有按照PS软件,可以参考其他方法,但是...
WPS对于办公人员来说是不陌生的,图片是必不可少的一项设计元素,如果要给图片加一个边框该怎么办呢?加框可以让图片更好看一些,在Word中想必大家都会,那么WPS中该如何操作呢?下面以图文的形式为大家介绍下,此法也适用于表格,演示中给图片加边框。大概步骤就是打开WPS文字并插入一张图片,接着将图片调到合适大小,并右键设置图片格式,在...
标签: Web开发
用法:  new Ajax().Request(url,cmd,async,method,postString,title)  参数:  url: 请求页面URL(必填)  cmd: 返回值处理函数(必填)  async: 是否异步 ,(ture|false), 默认true  method: 请求方式,(post|get), 默认get  postString: 请求方式为pos...

经验教程

504

收藏

49
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部