Hello,
I just downloaded your trial aspose.imaging for .Net C#
I want to place an image watermark on image using Aspose.Imaging
How can I place single watermark on bottom right corner of the image 50px from right and 50 px from bottom. My watermark dimensions are 130px width and 30px height.
I need a code example with C#. Thank you
@jamespage
Please review following code, weather it suites your expectations :
public void Run(string outputFolder)
{
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
using (var image = Image.Create(new JpegOptions { Source = new FileCreateSource(Path.Combine(this.TestDirectory, "Forum", "238083", "Watermark.jpg"), false) }, 1000, 1000))
{
var layoutArea = new SizeF(130, 30);
var padding = new SizeF(50, 50);
PutWatermark(new Graphics(image) { TextRenderingHint = TextRenderingHint.AntiAlias }, new PointF(image.Width - layoutArea.Width - padding.Width, image.Height - layoutArea.Height - padding.Height), layoutArea, "Hello world!", new Font("Tahoma", 16, FontStyle.Italic));
image.Save();
}
}
private void PutWatermark(Graphics graphics, PointF anchorPoint, SizeF layoutArea, string text, Font font)
{
graphics.Clear(Color.AntiqueWhite);
graphics.PageUnit = GraphicsUnit.Pixel;
var stringfomat = new StringFormat(StringFormat.GenericTypographic) { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
graphics.MeasureString(text, font, layoutArea, stringfomat);
graphics.DrawRectangle(new Pen(Color.LightGray), new RectangleF(anchorPoint.X, anchorPoint.Y, layoutArea.Width, layoutArea.Height));
graphics.DrawString(text, font, new Aspose.Imaging.Brushes.SolidBrush(Color.Black), anchorPoint.X + layoutArea.Width / 2, anchorPoint.Y + layoutArea.Height / 2, stringfomat);
}
Expected results : Watermark.jpg (7.7 KB)
Hello,
Thank you for the code.
my watermark is PNG image with transparent background (logo of the company)
how to use image watermark. Please help thank you
@jamespage
Please look at image overlay with transparency example below :
using (var image = (RasterImage)Image.Create(new PngOptions { Source = new FileCreateSource("WatermarkOn.png", false), ColorType = PngColorType.TruecolorWithAlpha }, 1000, 1000))
{
using (var watermarkImage = Image.Load("Watermark.png"))
{
Graphics graphics = new Graphics(image);
graphics.Clear(Color.Aqua);
graphics.DrawImage(watermarkImage, image.Width - watermarkImage.Width - padding.Width, image.Height - watermarkImage.Height - padding.Height, watermarkImage.Width, watermarkImage.Height);
}
image.Save();
}
Expected results : WatermarkOn.png (2.3 KB) using watermark image Watermark.png (759 Bytes)