麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

C# 添加圖片水印類的方法

2024-09-07 17:05:38
字體:
來源:轉載
供稿:網友
C# 添加圖片水印類的方法,它舉例分析了圖像中添加水印的方法,同時也分析了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
{
///

/// 給圖片上水印
///


///原圖片地址
///水印圖片地址
///
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
{ }
}
}
}
}

上文是關于C# 添加圖片水印類的方法介紹,相信大家都有了一定的了解,想要了解更多的技術信息,請繼續關注錯新技術頻道吧!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 91香草视频| 欧美性生交zzzzzxxxxx | 国产成人精品一区二区仙踪林 | 毛片大全 | 91麻豆精品国产91久久久无需广告 | 成人在线视频国产 | 国产一级免费片 | 91在线精品亚洲一区二区 | 久久华人| 亚洲第一精品在线 | 91成人免费视频 | 久久国产综合视频 | 精国品产一区二区三区有限公司 | 蜜桃视频在线免费观看 | 亚洲国产女同久久 | 亚洲成人激情av | 色诱亚洲精品久久久久久 | 91九色福利| 久久国产精品99国产 | 逼特逼视频在线观看 | 久久毛片 | 国产精品视频导航 | 国产欧美日韩在线不卡第一页 | 欧美一级做性受免费大片免费 | 亚洲精品一区二区三区大胸 | av电影在线观看网站 | 日本xxxx视频| 久久久久久99 | 亚洲导航深夜福利涩涩屋 | 大片毛片 | 国产精品99久久久久久久女警 | 精品国产一区二区三 | 精品不卡 | 永久免费黄色大片 | 未成年人在线观看 | 国产午夜电影在线观看 | 日韩色视频在线观看 | 黄色av电影在线播放 | 依依成人精品视频 | 国产一有一级毛片视频 | 欧美一级做a |