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!