无为清净楼资源网 Design By www.qnjia.com
复制代码 代码如下:
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
{ }
}
}
}
}

标签:
C#,图片水印

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。