四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

C# 添加圖片水印類實現代碼

復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Web;
using System.Drawing.Drawing2D;
using System.Reflection;
namespace Chen
{
public class warterPic
{
/// <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 = filepath;//修改的圖像路徑
int lucencypercent = 25;
Image modifyimage = null;
Image drawedimage = null;
Graphics g = null;
try
{
//建立圖形對象
modifyimage = Image.FromFile(modifyimagepath, true);
drawedimage = Image.FromFile(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
{ }
}
}
}
}

AspNet技術C# 添加圖片水印類實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 消防稳压罐安装图正规安装图| 托比·斯蒂芬斯| 第一财经今日股市直播间在线直播| cgtn news在线直播| 必修二英语课本电子版| 电影《斯宾塞》| 影片 - theav| 辘轳女人和井全26集 | 定型枕什么时候能给宝宝用| 我心灿烂| 电影同船爱歌| 澳门风云2演员表| 回到十八岁| 《优越极限》在线观看免费韩剧| 火船 电影| 刑事侦缉档案3演员表| 大海中的船原唱歌词| 汤唯和梁朝伟拍戏原版视频| 但愿人长久| 天津电视台节目表| kiss the rain钢琴谱| 看黄在线看| 朱莉娅·安经典在线观看| 电视剧《反击》主要演员| 弟子规电子版(可打印)| 同性gay| 西野翔电影| 曹查理电影大全免费观看国语| 部队飞行安全大讨论心得体会| jenna haze| 杨幂一级毛片在线播放| 战狼15电影在线观看| 决胜法庭演员表| 燃烧的岁月| 大浴女电视剧所有演员表| 辐射避难所掉脑袋问题答案| angelina全集在线观看| 经典影片小迷妹| 小猪佩奇免费版中文第三季| 十八岁在线观看| 《最后的凶手》免费观看|