好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ASP.NET(C#)图片加文字、图片水印

ASP.NET(C#)图片加文字、图片水印

http://blog.csdn.net/wonsoft/archive/2009/04/29/4136711.aspx

ASP.NET(C#)图片加文字、图片水印

一、图片上加文字:

 

//using System.Drawing;    //using System.IO;    //using System.Drawing.Imaging;       private   void  AddTextToImg( string  fileName, string  text)   {       if (!File.Exists(MapPath(fileName)))      {           throw   new  FileNotFoundException( "The file don't exist!" );      }             if ( text ==  string .Empty )      {           return ;      }       //还需要判断文件类型是否为图像类型,这里就不赘述了          System.Drawing.Image image = System.Drawing.Image.FromFile(MapPath(fileName));      Bitmap bitmap =  new  Bitmap(image,image.Width,image.Height);      Graphics g = Graphics.FromImage(bitmap);          float  fontSize = 12.0f;     //字体大小        float  textWidth = text.Length*fontSize;   //文本的长度        //下面定义一个矩形区域,以后在这个矩形里画上白底黑字        float  rectX = 0;               float  rectY = 0;       float  rectWidth = text.Length*(fontSize+8);       float  rectHeight = fontSize+8;       //声明矩形域       RectangleF textArea =  new  RectangleF(rectX,rectY,rectWidth,rectHeight);         Font font =  new  Font( "宋体" ,fontSize);    //定义字体       Brush whiteBrush =  new  SolidBrush(Color.White);    //白笔刷,画文字用       Brush blackBrush =  new  SolidBrush(Color.Black);    //黑笔刷,画背景用          g.FillRectangle(blackBrush,rectX,rectY,rectWidth,rectHeight);            g.DrawString(text,font,whiteBrush,textArea);      MemoryStream ms =  new  MemoryStream( );       //保存为Jpg类型       bitmap.Save(ms,ImageFormat.Jpeg);          //输出处理后的图像,这里为了演示方便,我将图片显示在页面中了       Response.Clear();      Response.ContentType =  "image/jpeg" ;      Response.BinaryWrite( ms.ToArray() );         g.Dispose();      bitmap.Dispose();      image.Dispose();   }  

二、图片上加水印:

 

//using System;     //using System.Web;     //using System.Drawing;     //using System.Drawing.Drawing2D;     //using System.Drawing.Imaging;     //using System.IO;     //using System.Reflection;        /// <summary>     /// 给图片上水印     /// </summary>     /// <param name="filePath">原图片地址</param>     /// <param name="waterFile">水印图片地址</param>     public   void  MarkWater( string  filePath, string  waterFile)    {         //GIF不水印          int  i = filePath.LastIndexOf( "." );         string  ex = filePath.Substring(i,filePath.Length - i);         if ( string .Compare(ex, ".gif" , true ) == 0)        {             return ;        }            string  ModifyImagePath = BasePath + filePath; //修改的图像路径          int  lucencyPercent=25;        Image modifyImage= null ;        Image drawedImage= null ;        Graphics g= null ;         try         {             //建立图形对象             modifyImage=Image.FromFile(ModifyImagePath, true );            drawedImage=Image.FromFile(BasePath + waterFile, true );            g=Graphics.FromImage(modifyImage);             //获取要绘制图形坐标              int  x=modifyImage.Width-drawedImage.Width;             int  y=modifyImage.Height-drawedImage.Height;             //设置颜色矩阵              float [][] matrixItems ={                 new   float [] {1, 0, 0, 0, 0},                 new   float [] {0, 1, 0, 0, 0},                 new   float [] {0, 0, 1, 0, 0},                 new   float [] {0, 0, 0, ( float )lucencyPercent/100f, 0},                 new   float [] {0, 0, 0, 0, 1}};               ColorMatrix colorMatrix =  new  ColorMatrix(matrixItems);            ImageAttributes imgAttr= new  ImageAttributes();            imgAttr.SetColorMatrix(colorMatrix,ColorMatrixFlag.Default,ColorAdjustType.Bitmap);             //绘制阴影图像             g.DrawImage(drawedImage, new  Rectangle(x,y,drawedImage.Width,drawedImage.Height),10,10,drawedImage.Width,drawedImage.Height,GraphicsUnit.Pixel,imgAttr);             //保存文件              string [] allowImageType={ ".jpg" , ".gif" , ".png" , ".bmp" , ".tiff" , ".wmf" , ".ico" };            FileInfo fi= new  FileInfo(ModifyImagePath);            ImageFormat imageType=ImageFormat.Gif;             switch (fi.Extension.ToLower())            {                 case   ".jpg" : imageType=ImageFormat.Jpeg;  break ;                 case   ".gif" : imageType=ImageFormat.Gif;  break ;                 case   ".png" : imageType=ImageFormat.Png;  break ;                 case   ".bmp" : imageType=ImageFormat.Bmp;  break ;                 case   ".tif" : imageType=ImageFormat.Tiff;  break ;                 case   ".wmf" : imageType=ImageFormat.Wmf;  break ;                 case   ".ico" : imageType=ImageFormat.Icon;  break ;                 default :  break ;            }            MemoryStream ms= new  MemoryStream();            modifyImage.Save(ms,imageType);             byte [] imgData=ms.ToArray();            modifyImage.Dispose();            drawedImage.Dispose();            g.Dispose();            FileStream fs= null ;            File.Delete(ModifyImagePath);            fs= new  FileStream(ModifyImagePath,FileMode.Create,FileAccess.Write);             if (fs!= null )            {                fs.Write(imgData,0,imgData.Length);                fs.Close();            }        }         finally         {             try             {                drawedImage.Dispose();                modifyImage.Dispose();                g.Dispose();            }             catch            {           }       }    }   

四、C#图片水印生成类(图片、文字、透明水印)

 

/*    * Class:WaterImage    * Use for add a water Image to the picture both words and image    * 2007.07.23   create the file    *    * http://www.freeatom.com/  欢迎您的来访    *     * 使用说明:    *  建议先定义一个WaterImage实例    *  然后利用实例的属性,去匹配需要进行操作的参数    *  然后定义一个WaterImageManage实例    *  利用WaterImageManage实例进行DrawImage(),印图片水印    *  DrawWords()印文字水印    *    -*/       using  System;   using  System.Drawing;   using  System.Drawing.Imaging;   using  System.Drawing.Drawing2D;   using  System.IO;   /// <summary>    /// 图片位置    /// </summary>    public   enum  ImagePosition   {       LeftTop,         //左上        LeftBottom,     //左下        RightTop,        //右上        RigthBottom,   //右下        TopMiddle,      //顶部居中        BottomMiddle,  //底部居中        Center            //中心    }      /// <summary>    /// 水印图片的操作管理 Design by Gary Gong From Demetersoft.com    /// </summary>    public   class  WaterImageManage   {        /// <summary>         /// 生成一个新的水印图片制作实例         /// </summary>         public  WaterImageManage ()       {            //             // TODO: Add constructor logic here             //        }           /// <summary>         /// 添加图片水印         /// </summary>         /// <param name="sourcePicture">源图片文件名</param>         /// <param name="waterImage">水印图片文件名</param>         /// <param name="alpha">透明度(0.1-1.0数值越小透明度越高)</param>         /// <param name="position">位置</param>         /// <param name="PicturePath" >图片的路径</param>         /// <returns>返回生成于指定文件夹下的水印文件名</returns>         public   string   DrawImage( string  sourcePicture,                                          string  waterImage,                                          float  alpha,                                         ImagePosition position,                                          string  PicturePath )       {            //             // 判断参数是否有效             //             if  (sourcePicture ==  string .Empty || waterImage ==  string .Empty || alpha == 0.0 || PicturePath ==  string .Empty)           {                return  sourcePicture;           }               //             // 源图片,水印图片全路径             //             string  sourcePictureName = PicturePath + sourcePicture;            string  waterPictureName = PicturePath + waterImage;            string  fileSourceExtension = System.IO.Path.GetExtension(sourcePictureName).ToLower();            string  fileWaterExtension = System.IO.Path.GetExtension(waterPictureName).ToLower();            //             // 判断文件是否存在,以及类型是否正确             //             if  (System.IO.File.Exists(sourcePictureName) ==  false  ||                System.IO.File.Exists(waterPictureName) ==  false  ||(               fileSourceExtension !=  ".gif"  &&               fileSourceExtension !=  ".jpg"  &&               fileSourceExtension !=  ".png" ) || (               fileWaterExtension !=  ".gif"  &&               fileWaterExtension !=  ".jpg"  &&               fileWaterExtension !=  ".png" )               )           {                return  sourcePicture;           }               //             // 目标图片名称及全路径             //             string  targetImage = sourcePictureName.Replace ( System.IO.Path.GetExtension(sourcePictureName), "" ) +  "_1101.jpg" ;               //             // 将需要加上水印的图片装载到Image对象中             //            Image imgPhoto = Image.FromFile(sourcePictureName);            //             // 确定其长宽             //             int  phWidth = imgPhoto.Width;            int  phHeight = imgPhoto.Height;               //             // 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。             //            Bitmap bmPhoto =  new  Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);               //             // 设定分辨率             //             bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);               //             // 定义一个绘图画面用来装载位图             //            Graphics grPhoto = Graphics.FromImage(bmPhoto);               //             //同样,由于水印是图片,我们也需要定义一个Image来装载它             //            Image imgWatermark =  new  Bitmap(waterPictureName);                       //             // 获取水印图片的高度和宽度             //             int  wmWidth = imgWatermark.Width;            int  wmHeight = imgWatermark.Height;               //SmoothingMode:指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘。             // 成员名称   说明              // AntiAlias      指定消除锯齿的呈现。               // Default        指定不消除锯齿。               // HighQuality  指定高质量、低速度呈现。               // HighSpeed   指定高速度、低质量呈现。               // Invalid        指定一个无效模式。               // None          指定不消除锯齿。             grPhoto.SmoothingMode = SmoothingMode.AntiAlias;               //             // 第一次描绘,将我们的底图描绘在绘图画面上             //            grPhoto.DrawImage(imgPhoto,                                                                                  new  Rectangle(0, 0, phWidth, phHeight),                                        0,                                            0,                                              phWidth,                                          phHeight,                                             GraphicsUnit.Pixel);                   //             // 与底图一样,我们需要一个位图来装载水印图片。并设定其分辨率             //            Bitmap bmWatermark =  new  Bitmap(bmPhoto);           bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);                       //             // 继续,将水印图片装载到一个绘图画面grWatermark             //            Graphics grWatermark = Graphics.FromImage(bmWatermark);               //             //ImageAttributes 对象包含有关在呈现时如何操作位图和图元文件颜色的信息。             //                   ImageAttributes imageAttributes =  new  ImageAttributes();               //             //Colormap: 定义转换颜色的映射             //            ColorMap colorMap =  new  ColorMap();               //             //我的水印图被定义成拥有绿色背景色的图片被替换成透明             //            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);           colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);              ColorMap[] remapTable = { colorMap };              imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);               float [][] colorMatrixElements = {                new   float [] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},  // red红色                new   float [] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},  //green绿色                new   float [] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},  //blue蓝色                       new   float [] {0.0f,  0.0f,  0.0f,  alpha, 0.0f},  //透明度                     new   float [] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}}; //                //  ColorMatrix:定义包含 RGBA 空间坐标的 5 x 5 矩阵。             //  ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色。            ColorMatrix wmColorMatrix =  new  ColorMatrix(colorMatrixElements);                 imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,            ColorAdjustType.Bitmap);               //             //上面设置完颜色,下面开始设置位置             //             int  xPosOfWm;            int  yPosOfWm;                switch  (position)           {                case  ImagePosition .BottomMiddle :                   xPosOfWm = (phWidth-wmWidth ) / 2 ;                   yPosOfWm = phHeight- wmHeight -10;                    break  ;                case  ImagePosition .Center :                   xPosOfWm = (phWidth - wmWidth) / 2;                   yPosOfWm = (phHeight-wmHeight ) / 2;                    break  ;                case  ImagePosition .LeftBottom :                   xPosOfWm = 10;                   yPosOfWm = phHeight - wmHeight - 10;                    break  ;                case  ImagePosition .LeftTop :                   xPosOfWm = 10;                   yPosOfWm = 10;                    break ;                case  ImagePosition .RightTop :                   xPosOfWm = phWidth - wmWidth - 10;                   yPosOfWm = 10;                    break  ;                case  ImagePosition .RigthBottom :                   xPosOfWm = phWidth - wmWidth - 10;                   yPosOfWm = phHeight - wmHeight - 10;                    break  ;                case  ImagePosition.TopMiddle :                   xPosOfWm = (phWidth - wmWidth) / 2;                   yPosOfWm = 10;                    break  ;                default :                   xPosOfWm = 10;                   yPosOfWm = phHeight - wmHeight - 10;                    break ;           }               //             // 第二次绘图,把水印印上去             //            grWatermark.DrawImage(imgWatermark,             new  Rectangle(xPosOfWm,                                yPosOfWm,                                wmWidth,                                wmHeight),                                 0,                                              0,                                          wmWidth,                                  wmHeight,                                   GraphicsUnit.Pixel,                                  imageAttributes);                         imgPhoto = bmWatermark;           grPhoto.Dispose();           grWatermark.Dispose();               //             // 保存文件到服务器的文件夹里面             //            imgPhoto.Save(targetImage, ImageFormat.Jpeg);           imgPhoto.Dispose();           imgWatermark.Dispose();            return  targetImage.Replace (PicturePath, "" );       }           /// <summary>         /// 在图片上添加水印文字         /// </summary>         /// <param name="sourcePicture">源图片文件</param>         /// <param name="waterWords">需要添加到图片上的文字</param>         /// <param name="alpha">透明度</param>         /// <param name="position">位置</param>         /// <param name="PicturePath">文件路径</param>         /// <returns></returns>         public   string  DrawWords( string  sourcePicture,                                          string  waterWords,                                          float  alpha,                                         ImagePosition position,                                          string  PicturePath)       {            //             // 判断参数是否有效             //             if  (sourcePicture ==  string .Empty || waterWords ==  string .Empty || alpha == 0.0 || PicturePath ==  string .Empty)           {                return  sourcePicture;           }               //             // 源图片全路径             //             string  sourcePictureName = PicturePath + sourcePicture;            string  fileExtension = System.IO.Path.GetExtension(sourcePictureName).ToLower();               //             // 判断文件是否存在,以及文件名是否正确             //             if  (System.IO.File.Exists(sourcePictureName) ==  false  || (               fileExtension !=  ".gif"   &&               fileExtension !=  ".jpg"  &&               fileExtension !=  ".png"  ))           {                return  sourcePicture;           }               //             // 目标图片名称及全路径             //             string  targetImage = sourcePictureName.Replace(System.IO.Path.GetExtension(sourcePictureName),  "" ) +  "_0703.jpg" ;               //创建一个图片对象用来装载要被添加水印的图片            Image imgPhoto = Image.FromFile(sourcePictureName);               //获取图片的宽和高             int  phWidth = imgPhoto.Width;            int  phHeight = imgPhoto.Height;               //             //建立一个bitmap,和我们需要加水印的图片一样大小            Bitmap bmPhoto =  new  Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);               //SetResolution:设置此 Bitmap 的分辨率             //这里直接将我们需要添加水印的图片的分辨率赋给了bitmap            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);               //Graphics:封装一个 GDI+ 绘图图面。            Graphics grPhoto = Graphics.FromImage(bmPhoto);               //设置图形的品质            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;               //将我们要添加水印的图片按照原始大小描绘(复制)到图形中            grPhoto.DrawImage(            imgPhoto,                                            //   要添加水印的图片              new  Rectangle(0, 0, phWidth, phHeight),  //  根据要添加的水印图片的宽和高             0,                                                      //  X方向从0点开始描绘             0,                                                      // Y方向              phWidth,                                             //  X方向描绘长度             phHeight,                                            //  Y方向描绘长度             GraphicsUnit.Pixel);                               // 描绘的单位,这里用的是像素                //根据图片的大小我们来确定添加上去的文字的大小             //在这里我们定义一个数组来确定             int [] sizes =  new   int [] { 16, 14, 12, 10, 8, 6, 4 };               //字体            Font crFont =  null ;            //矩形的宽度和高度,SizeF有三个属性,分别为Height高,width宽,IsEmpty是否为空            SizeF crSize =  new  SizeF();               //利用一个循环语句来选择我们要添加文字的型号             //直到它的长度比图片的宽度小             for  ( int  i = 0; i < 7; i++)           {               crFont =  new  Font( "arial" , sizes[i], FontStyle.Bold);                   //测量用指定的 Font 对象绘制并用指定的 StringFormat 对象格式化的指定字符串。                crSize = grPhoto.MeasureString(waterWords, crFont);                   // ushort 关键字表示一种整数数据类型                 if  (( ushort )crSize.Width < ( ushort )phWidth)                    break ;           }               //截边5%的距离,定义文字显示(由于不同的图片显示的高和宽不同,所以按百分比截取)             int  yPixlesFromBottom = ( int )(phHeight * .05);               //定义在图片上文字的位置             float  wmHeight =  crSize.Height;            float  wmWidth = crSize .Width ;               float   xPosOfWm;            float   yPosOfWm;                switch  (position)           {                case  ImagePosition .BottomMiddle :                   xPosOfWm = phWidth / 2 ;                   yPosOfWm = phHeight- wmHeight -10;                    break  ;                case  ImagePosition .Center :                   xPosOfWm = phWidth / 2;                   yPosOfWm = phHeight / 2;                    break  ;                case  ImagePosition .LeftBottom :                   xPosOfWm = wmWidth;                   yPosOfWm = phHeight - wmHeight - 10;                    break  ;                case  ImagePosition .LeftTop :                   xPosOfWm = wmWidth/2 ;                   yPosOfWm = wmHeight / 2;                    break ;                case  ImagePosition .RightTop :                   xPosOfWm = phWidth - wmWidth - 10;                   yPosOfWm = wmHeight;                    break  ;                case  ImagePosition .RigthBottom :                   xPosOfWm = phWidth - wmWidth - 10;                   yPosOfWm = phHeight - wmHeight - 10;                    break  ;                case  ImagePosition.TopMiddle :                   xPosOfWm = phWidth / 2;                   yPosOfWm = wmWidth;                    break  ;                default :                   xPosOfWm = wmWidth;                   yPosOfWm = phHeight - wmHeight - 10;                    break ;           }               //封装文本布局信息(如对齐、文字方向和 Tab 停靠位),显示操作(如省略号插入和国家标准 (National) 数字替换)和 OpenType 功能。            StringFormat StrFormat =  new  StringFormat();               //定义需要印的文字居中对齐            StrFormat.Alignment = StringAlignment.Center;               //SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。             //这个画笔为描绘阴影的画笔,呈灰色             int  m_alpha = Convert .ToInt32 ( 256 * alpha);           SolidBrush semiTransBrush2 =  new  SolidBrush(Color.FromArgb(m_alpha, 0, 0, 0));               //描绘文字信息,这个图层向右和向下偏移一个像素,表示阴影效果             //DrawString 在指定矩形并且用指定的 Brush 和 Font 对象绘制指定的文本字符串。            grPhoto.DrawString(waterWords,                                     //string of text                                       crFont,                                          //font                                       semiTransBrush2,                             //Brush                                        new  PointF(xPosOfWm + 1, yPosOfWm + 1),   //Position                                       StrFormat);               //从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153             //这个画笔为描绘正式文字的笔刷,呈白色            SolidBrush semiTransBrush =  new  SolidBrush(Color.FromArgb(153, 255, 255, 255));               //第二次绘制这个图形,建立在第一次描绘的基础上            grPhoto.DrawString(waterWords,                  //string of text                                       crFont,                                    //font                                       semiTransBrush,                            //Brush                                        new  PointF(xPosOfWm, yPosOfWm),   //Position                                       StrFormat);               //imgPhoto是我们建立的用来装载最终图形的Image对象             //bmPhoto是我们用来制作图形的容器,为Bitmap对象            imgPhoto = bmPhoto;            //释放资源,将定义的Graphics实例grPhoto释放,grPhoto功德圆满            grPhoto.Dispose();               //将grPhoto保存            imgPhoto.Save(targetImage, ImageFormat.Jpeg);           imgPhoto.Dispose();               return  targetImage.Replace(PicturePath,  "" );       }   }      /// <summary>    /// 装载水印图片的相关信息    /// </summary>    public   class  WaterImage   {        public  WaterImage ()       {          }           private   string  m_sourcePicture;        /// <summary>         /// 源图片地址名字(带后缀)         /// </summary>         public   string  SourcePicture       {            get  {  return  m_sourcePicture; }            set  { m_sourcePicture = value; }       }           private   string   m_waterImager;        /// <summary>         /// 水印图片名字(带后缀)         /// </summary>         public   string   WaterPicture       {            get  {  return  m_waterImager; }            set  { m_waterImager = value; }       }           private   float   m_alpha;        /// <summary>         /// 水印图片文字的透明度         /// </summary>         public   float   Alpha       {            get  {  return  m_alpha; }            set  { m_alpha = value; }       }           private  ImagePosition  m_postition;        /// <summary>         /// 水印图片或文字在图片中的位置         /// </summary>         public  ImagePosition  Position       {            get  {  return  m_postition; }            set  { m_postition = value; }       }           private   string   m_words;        /// <summary>         /// 水印文字的内容         /// </summary>         public   string   Words       {            get  {  return  m_words; }            set  { m_words = value; }       }           }  

三、 图片+水印(透明)函数

 

<summary>       /// 添加图片水印        /// </summary>        /// <param name="path">原图片绝对地址</param>        /// <param name="Ext">文件后缀</param>        public   static   string  addWaterMark( string  path, string  fileExt)      {       System.Drawing.Image image = System.Drawing.Image.FromFile(path);       Bitmap b =  new  Bitmap(image.Width, image.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);       Graphics g = Graphics.FromImage(b);       g.Clear(Color.White);       g.DrawImage(image, 0, 0, image.Width, image.Height);          Image watermark =  new  Bitmap(ConfigurationSettings.AppSettings[ "PersonalPath" ] + @ "images\logo.jpg" );          System.Drawing.Imaging.ImageAttributes imageAttributes =  new  System.Drawing.Imaging.ImageAttributes();       System.Drawing.Imaging.ColorMap colorMap =  new  System.Drawing.Imaging.ColorMap();       colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);       colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);       System.Drawing.Imaging.ColorMap[] remapTable = {colorMap};       imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);        float [][] colorMatrixElements = {                 new   float [] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},                 new   float [] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},                 new   float [] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},                 new   float [] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},                 new   float [] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}               };       System.Drawing.Imaging.ColorMatrix colorMatrix =  new  System.Drawing.Imaging.ColorMatrix(colorMatrixElements);       imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);        int  xpos = 0;        int  ypos = 0;             xpos = ((image.Width - watermark.Width) - 10);       ypos = image.Height - watermark.Height - 10;          g.DrawImage(watermark,  new  Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);          watermark.Dispose();       imageAttributes.Dispose();              //保存加水印过后的图片,删除原始图片        Random ro= new  Random(( int )DateTime.Now.Ticks);        string  temppath = System.DateTime.Now.ToString( "yyyy" ) +  "\\" + System.DateTime.Now.ToString(" MMdd");        string  fileName = temppath +  "\\" + DateTime.Now.ToString(" yyyyMMddHHmmss") + ro.Next(10000) + fileExt;        string  filepath = Functions.GetUserFactPath(User.GetUserFromSession().Adddate,User.GetUserFromSession().UserId) +  "3\\" ;                b.Save(filepath + fileName);       b.Dispose();       image.Dispose();        if (File.Exists(path))       {        File.Delete(path);       }           return  fileName;      }  

08 2010 档案

 

sd

摘要: using System;using System.Collections.Generic;using System.Collections;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using System.Drawing;using... 阅读全文

posted @  2010-08-14 15:17  sikaodelang 阅读(108) |  评论 (0)   编辑

 

sdd

摘要: using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Drawing;using System.Drawing.Design;using System.Drawi... 阅读全文

posted @  2010-08-10 18:06  sikaodelang 阅读(70) |  评论 (0)   编辑

 

修改

摘要: using System;using System.Collections.Generic;using System.Collections;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using System.Drawing;using... 阅读全文

posted @  2010-08-10 18:02  sikaodelang 阅读(36) |  评论 (0)   编辑

 

ASP.NET(C#)图片加文字、图片水印

摘要: http://blog.csdn.net/wonsoft/archive/2009/04/29/4136711.aspxASP.NET(C#)图片加文字、图片水印一、图片上加文字://usingSystem.Drawing;//usingSystem.IO;//usingSystem.Drawing.Imaging;privatevoidAddTextToImg(stringfileName,st... 阅读全文

posted @  2010-08-10 17:47  sikaodelang 阅读(850) |  评论 (1)   编辑

 

up

摘要: http://www.cnblogs.com/wangergo/archive/2006/05/31/414239.html 阅读全文

posted @  2010-08-09 17:17  sikaodelang 阅读(3) |  评论 (0)   编辑

 

监听EditText内容变化

摘要: 1、给EditText追加ChangedListenerEditText editText = (EditText) findViewById(R.id.edittext);editText.addTextChangedListener(watcher);2、描述监听private TextWatcher watcher = new TextWatcher() { @Override public... 阅读全文

posted @  2010-08-06 10:47  sikaodelang 阅读(68) |  评论 (0)   编辑

 

自定义下拉菜单模式

摘要: http://www.cnblogs.com/alex77lee/archive/2010/08/04/1792454.html 阅读全文

posted @  2010-08-06 10:45  sikaodelang 阅读(9) |  评论 (0)   编辑

 

构建自定义组件

摘要: From:http://blog.csdn.net/shiqx429/archive/2009/02/06/3865581.aspx 阅读全文

posted @  2010-08-06 10:28  sikaodelang 阅读(6) |  评论 (0)   编辑

 

Activity生命周期详解

摘要: Reprinted:http://kb.cnblogs.com/page/70125/ 阅读全文

posted @  2010-08-06 09:58  sikaodelang 阅读(11) |  评论 (0)   编辑

 

防sql注入

摘要: http://www.cnblogs.com/ocean/archive/2005/02/22/107250.html 阅读全文

posted @  2010-08-04 11:52  sikaodelang 阅读(6) |  评论 (0)   编辑

 

学习网站

摘要: http://phinecos.cnblogs.com/ 阅读全文

posted @  2010-08-03 15:30  sikaodelang 阅读(9) |  评论 (0)   编辑

 

史上最详细口语练习法!

摘要: 编辑点评:作者曾创下10天背完1万GRE单词的惊人记录,目前在美国留学的她和网友们分享了自己的口语练习方法,不学术、非常实用![1] 考拉的练习方法[2] 考拉答同学问 中英双语 英文 中文 本文相关应用 贡献文章录音 贡献翻译稿 贡献听写稿 下载本文音频 背单词 鼠标划词已启用 挑错 收藏 评论 打印 我明白咱们中国学生最怵的就是口语部分,因为通常单词背背就会了,写作搞一个模板也能高分了,往往... 阅读全文

posted @  2010-08-03 14:13  sikaodelang 阅读(46) |  评论 (0)   编辑

 

史上最详细单词记忆法!

摘要: 编辑点评:作者曾创下10天背完1万GRE单词的惊人记录,目前在美国留学的她为网友们总结了巨细糜遗的背单词方法,为单词痛苦的你还不快进来看看?[1] 考拉的背词方法及背词经历[2] 考拉答同学问 中英双语 英文 中文 本文相关应用 贡献文章录音 贡献翻译稿 贡献听写稿 下载本文音频 背单词 鼠标划词已启用 挑错 收藏 评论 打印 因为单词是万事的基础,所以决定把单词提到前面来写。1. 考拉的背词经... 阅读全文

posted @  2010-08-03 14:12  sikaodelang 阅读(16) |  评论 (0)   编辑

 

Android监听呼出电话

摘要: Android监听呼出电话http://www.cnblogs.com/jackmouse/archive/2010/05/14/1735032.html 阅读全文

posted @  2010-08-03 13:59  sikaodelang 阅读(26) |  评论 (0)   编辑

《Android/OPhone 开发完全讲义》样章和目录下载

摘要: http://www.cnblogs.com/nokiaguy/archive/2010/06/02/1749959.html 阅读全文

posted @  2010-07-31 14:58  sikaodelang 阅读(9) |  评论 (0)   编辑

 

Android系统原理与源码分析(1):利用Java反射技术阻止通过按钮关闭对话框

摘要: http://www.cnblogs.com/nokiaguy/archive/2010/07/27/1786482.html 阅读全文

posted @  2010-07-31 14:36  sikaodelang 阅读(37) |  评论 (0)   编辑

 

Android中Bitmap.createBitmap重载方总结 和 Android实现位图剪切

摘要: http://www.cnblogs.com/igrl/archive/2010/07/30/Bitmap_createBitmap.html 阅读全文

posted @  2010-07-31 14:29  sikaodelang 阅读(90) |  评论 (0)   编辑

 

实现基于Android的英文电子词典

摘要: From: http://www.cnblogs.com/nokiaguy/archive/2010/07/31/1789218.html 阅读全文

posted @  2010-07-31 14:28  sikaodelang 阅读(28) |  评论 (0)   编辑

 

c# 客户端更新的三种方法 tcp/ip……

摘要: http://www.cnblogs.com/wengjinbao/archive/2009/09/25/1573783.html 阅读全文

posted @  2010-07-23 16:11  sikaodelang 阅读(346) |  评论 (0)   编辑

作者: Leo_wl

    

出处: http://www.cnblogs.com/Leo_wl/

    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

版权信息

查看更多关于ASP.NET(C#)图片加文字、图片水印的详细内容...

  阅读:33次