IC.CoolWatermark.dll vs Graphics - 性能速度 [英] IC.CoolWatermark.dll vs Graphics - perfomance speed

查看:65
本文介绍了IC.CoolWatermark.dll vs Graphics - 性能速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





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!

推荐答案

如果你已经开发了代码对于所有方法,只需使用类 System.Diagnostics.Stopwatch 类解决一些特征任务由一个和另一个解决的问题:

http://msdn.microsoft.com/en-us/library/ system.diagnostics.stopwatch%28v = vs.110%29.aspx [ ^ ]。



在计时中,有一个微妙的时刻:你必须从时间中排除JIT编译器。由于编译器基于每个方法工作,您需要做一件简单的事情来实现:在开始计时之前至少调用所涉及的所有方法一次。有关JIT的理解,请参阅: http://en.wikipedia.org/wiki/Just-in-time_compilation [ ^ ]。



-SA
If you already developed the code for all methods, just time some characteristic tasks solved by one and another one, using the class System.Diagnostics.Stopwatch:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch%28v=vs.110%29.aspx[^].

In timing, there is one delicate moment: you have to exclude JIT compiler from timing. As the compiler works on per-method basis, you need to do one simple thing to achieve that: call all the methods involved at least once before you start timing. For understanding JIT, please see: http://en.wikipedia.org/wiki/Just-in-time_compilation[^].

—SA


这篇关于IC.CoolWatermark.dll vs Graphics - 性能速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆