问题描述
i需要在图像上添加水印。
i以双向方式进行水印。
第一种方法,
使用IC.CoolWatermark.dll
string WaterMarkText =Comp Name; //水印文本
System.Drawing.Image bitmap = System.Drawing.Image.FromStream(stream); //从数据库获取图像
IC.CoolWatermark.Writer writer = new Writer(bitmap);
writer.PositionStyle = PositionStyle.MiddleCenter ;
writer.Shadow = new Shadow(Color.Transparent,0,0);
writer.FontStyle = FontStyle.Regular;
writer .Border = new Border(Pens.Gray);
writer.FontFamily = new FontFamily(Cambria);
writer.FontSize = watermarkfontsize(writer.Image.Width );
writer.Colors [0] = Color.Transparent;
IC.CoolWatermark.Shape shape = new IC.CoolWatermark.Shape();
shape.ShapeStyle = IC.CoolWatermark.ShapeStyle.ShearVertical;
writer.Shape = shape;
writer.Angle = 320;
bitmap = new Bitm ap(writer.WriteText(WaterMarkText));
MemoryStream oStream = new MemoryStream();
bitmap.Save(oStream,System。 Drawing.Imaging.ImageFormat.Png);
context.Response.BinaryWrite(oStream.ToArray());
bitmap.Dispose();
第二种方式:
使用System.Drawing.Graphics
string path = context.Server.MapPath(〜/ Image / water_02.png); //水印图片
位图_watermarkImage =新位图(路径); //水印图片
位图_baseImage = new Bitmap(stream); //来自数据库的图像应该与水印图像重叠
//从左边10个像素和从基础图像顶部10个像素绘制水印偏移。 br />
图形画布= Graphics.FromImage(_baseImage);
canvas .DrawImage(_watermarkImage,new Rectangle(20,10,_ watermarkImage.Width,_watermarkImage.Height),0,10,
_watermarkImage.Width,
_watermarkImage.Height,
GraphicsUnit.Pixel);
canvas.Save();
_baseImage.Save(context.Response.OutputStream,ImageFormat.Jpeg);
//清理
_baseImage.Dispose();
canvas.Dispose();
在第一种方法中,我使用IC.CoolWatermark.dll编写文本。但是在sencod方法中,我正在绘制图像以将两个图像重叠在一起。
两者都是有效的。但是哪一个最适合表现明智。哪一个我可以用于我的项目?
谢谢!
Hi,
i need to watermark on images.
i did it in two way.
first method,
using IC.CoolWatermark.dll
string WaterMarkText = "Comp Name"; // watermark text
System.Drawing.Image bitmap = System.Drawing.Image.FromStream(stream); // got image from database
IC.CoolWatermark.Writer writer = new Writer(bitmap);
writer.PositionStyle = PositionStyle.MiddleCenter;
writer.Shadow = new Shadow(Color.Transparent, 0, 0);
writer.FontStyle = FontStyle.Regular;
writer.Border = new Border(Pens.Gray);
writer.FontFamily = new FontFamily("Cambria");
writer.FontSize = watermarkfontsize(writer.Image.Width);
writer.Colors[0] = Color.Transparent;
IC.CoolWatermark.Shape shape = new IC.CoolWatermark.Shape();
shape.ShapeStyle = IC.CoolWatermark.ShapeStyle.ShearVertical;
writer.Shape = shape;
writer.Angle = 320;
bitmap = new Bitmap(writer.WriteText(WaterMarkText));
MemoryStream oStream = new MemoryStream();
bitmap.Save(oStream, System.Drawing.Imaging.ImageFormat.Png);
context.Response.BinaryWrite(oStream.ToArray());
bitmap.Dispose();
second way:
using " System.Drawing.Graphics"
string path = context.Server.MapPath("~/Image/water_02.png"); // watermark image
Bitmap _watermarkImage = new Bitmap(path); // watermark image
Bitmap _baseImage = new Bitmap(stream); // image from database which should overlap with watermark image
//Draw the watermark offset 10 pixels from the left and 10 pixels from the top of the base image.
Graphics canvas = Graphics.FromImage(_baseImage);
canvas.DrawImage(_watermarkImage,new Rectangle(20, 10, _watermarkImage.Width, _watermarkImage.Height), 0, 10,
_watermarkImage.Width,
_watermarkImage.Height,
GraphicsUnit.Pixel);
canvas.Save();
_baseImage.Save(context.Response.OutputStream, ImageFormat.Jpeg);
//clean up
_baseImage.Dispose();
canvas.Dispose();
In first method, i am writing text using IC.CoolWatermark.dll. But in sencod method i am drawing image to get overlapped two images together.
Both are works. But which one is best in order performance wise. which one i can use for my project?
Thanks!
推荐答案
这篇关于IC.CoolWatermark.dll vs Graphics - 性能速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!