Click here to Skip to main content
15,908,015 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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!
Posted

1 solution

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
 
Share this answer
 
Comments
christhuxavier 30-Jul-14 3:00am    
Thanks a lot.. i will check
Sergey Alexandrovich Kryukov 30-Jul-14 11:29am    
You a very welcome.
Good luck, call again.
—SA
christhuxavier 14-Aug-14 0:21am    
hi Sergey!.. thanks a lot again. i got the performance through your suggestion.
Sergey Alexandrovich Kryukov 14-Aug-14 1:55am    
Really? Such a pleasure to hear about your success, thank you very much for sending a note.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900