中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

C#.NET添加圖片水印

using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.IO;namespace Pub.Class{    ///<summary>/// 添加水印類 只支持添加圖片水印    ///</summary>publicclass Watermark    {        #region 私有成員
        privatestring modifyImagePath=null;  privatestring drawedImagePath=null;  privateint rightSpace;  privateint bottoamSpace;  privateint lucencyPercent=70;  privatestring outPath=null;        #endregion#region 構造器
        ///<summary>/// 構造函數        ///</summary>public Watermark() { }        #endregion#region 屬性
        ///<summary>/// 獲取或設置要修改的圖像路徑  ///</summary>publicstring ModifyImagePath  {   get{returnthis.modifyImagePath;}   set{this.modifyImagePath=value;}  }  ///<summary>/// 獲取或設置在畫的圖片路徑(水印圖片)  ///</summary>publicstring DrawedImagePath  {   get{returnthis.drawedImagePath;}   set{this.drawedImagePath=value;}  }  ///<summary>/// 獲取或設置水印在修改圖片中的右邊距  ///</summary>publicint RightSpace  {   get{returnthis.rightSpace;}   set{this.rightSpace=value;}  }  ///<summary>/// 獲取或設置水印在修改圖片中距底部的高度  ///</summary>publicint BottoamSpace  {   get{returnthis.bottoamSpace;}   set{this.bottoamSpace=value;}  }  ///<summary>/// 獲取或設置要繪制水印的透明度,注意是原來圖片透明度的百分比  ///</summary>publicint LucencyPercent  {   get{returnthis.lucencyPercent;}   set { if(value>=0&&value<=100) this.lucencyPercent=value; }  }  ///<summary>/// 獲取或設置要輸出圖像的路徑  ///</summary>publicstring OutPath  {   get{returnthis.outPath;}   set{this.outPath=value;}        }        #endregion#region 開始繪制水印 DrawImage
        ///<summary>/// 開始繪制水印  ///</summary>///<example>///<code>///     Watermark wm = new Watermark();        ///     wm.DrawedImagePath= Server.MapPath("") + "/upfile/" + "backlogo.gif";        ///     wm.ModifyImagePath=path;         ///     wm.RightSpace=184;        ///     wm.BottoamSpace=81;        ///     wm.LucencyPercent=50;        ///     wm.OutPath=Server.MapPath("") + "/upfile/" + fileName + "_new" + extension;        ///     wm.DrawImage();        //////     //保存加水印過后的圖片,刪除原始圖片         ///     mFileName=fileName + "_new" + extension;        ///     if(File.Exists(path)) {  File.Delete(path); }         ///</code>///</example>publicvoid DrawImage()  {   Image modifyImage=null;   Image drawedImage=null;   Graphics g=null;   try {     modifyImage=Image.FromFile(this.ModifyImagePath);//建立圖形對象
    drawedImage=Image.FromFile(this.DrawedImagePath);    g=Graphics.FromImage(modifyImage);        int x=modifyImage.Width-this.rightSpace;//獲取要繪制圖形坐標int y=modifyImage.Height-this.BottoamSpace;        float[][] matrixItems ={//設置顏色矩陣newfloat[] {1, 0, 0, 0, 0},            newfloat[] {0, 1, 0, 0, 0},            newfloat[] {0, 0, 1, 0, 0},            newfloat[] {0, 0, 0, (float)this.LucencyPercent/100f, 0},            newfloat[] {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),     0,0,drawedImage.Width,drawedImage.Height,     GraphicsUnit.Pixel,imgAttr);        string[] allowImageType={".jpg",".gif",".png",".bmp",".tiff",".wmf",".ico"};//保存文件
    FileInfo file=new FileInfo(this.ModifyImagePath);    ImageFormat p_w_picpathType=ImageFormat.Gif;    switch(file.Extension.ToLower()) {     case".jpg": p_w_picpathType=ImageFormat.Jpeg; break;     case".gif": p_w_picpathType=ImageFormat.Gif; break;     case".png": p_w_picpathType=ImageFormat.Png; break;     case".bmp": p_w_picpathType=ImageFormat.Bmp; break;     case".tif": p_w_picpathType=ImageFormat.Tiff; break;     case".wmf": p_w_picpathType=ImageFormat.Wmf; break;     case".ico": p_w_picpathType=ImageFormat.Icon; break;     default: break;    }    MemoryStream ms=new MemoryStream();    modifyImage.Save(ms,p_w_picpathType);    byte[] imgData=ms.ToArray();    modifyImage.Dispose();    drawedImage.Dispose();    g.Dispose();    FileStream fs=null;    if(this.OutPath==null || this.OutPath=="") {     File.Delete(this.ModifyImagePath);     fs=new FileStream(this.ModifyImagePath,FileMode.Create,FileAccess.Write);    } else {     fs=new FileStream(this.OutPath,FileMode.Create,FileAccess.Write);    }    if(fs!=null) {     fs.Write(imgData,0,imgData.Length);     fs.Close();    }   } finally {    try {     drawedImage.Dispose();     modifyImage.Dispose();     g.Dispose();    } catch{}   }  }        #endregion    }}
 

當前名稱:C#.NET添加圖片水印
轉載注明:http://m.2m8n56k.cn/article8/jdchop.html

成都網站建設公司_創新互聯,為您提供Google全網營銷推廣網站內鏈App設計網站制作

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站優化排名
主站蜘蛛池模板: 国产成人亚洲综合欧美一部 | 99re久久资源最新地址 | 亚洲欧美日本在线观看 | 国产精品福利视频萌白酱 | 欧美日一本 | 亚洲国产成人精彩精品 | 国产一级特黄一级毛片 | 免费看三级毛片 | 一区二区三区 日韩 | 中文字幕亚洲欧美日韩不卡 | 国产一区国产二区国产三区 | 手机看片日本 | 免费成人高清视频 | 成人爱爱网站在线观看 | 特级a毛片 | 日韩在线精品 | 亚洲精品久久久久久久网站 | 一级做a爰片久久毛片欧美 一级做a爰片久久毛片人呢 | 国产美女视频一区 | 在线观看中文字幕亚洲 | 2020亚洲男人天堂 | 日韩欧美国产高清在线观看 | 波多野结衣视频免费在线观看 | 国产精品高清久久久久久久 | 男女视频免费 | 中文字幕乱码中文乱码综合 | 97视频免费在线观看 | 99福利资源久久福利资源 | 亚洲精品一区二区三区四 | 亚洲国产精品成人午夜在线观看 | a级国产乱理伦片在线 | 一级毛片无毒不卡直接观看 | 一级色黄| 日本免费网站视频www区 | 国产精品久久久久久久专区 | 亚洲一区二区三区免费看 | 在线观看国产精成人品 | 亚洲色视频在线播放网站 | 午夜久久视频 | 在线观看国产精品一区 | 青青自拍视频一区二区三区 |