//
// This code is part of Document Solutions for Imaging demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;
using GCTEXT = GrapeCity.Documents.Text;
using GCDRAW = GrapeCity.Documents.Drawing;
namespace DsImagingWeb.Demos
{
// This sample demonstrates how to add a text watermark
// to an image. The image is rendered using its native
// resolution on a GcBitmap, then the watermark text
// is drawn on top using a semitransparent color.
// The resulting bitmap with the added watermark
// can be saved to any of the supported image formats.
public class Watermark
{
public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
{
var Inch = dpi;
var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
using (var g = bmp.CreateGraphics(Color.LightGray))
using (var image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "reds.jpg")))
{
var rc = new RectangleF((pixelSize.Width - image.Width) / 2, (pixelSize.Height - image.Height) / 2, image.Width, image.Height);
g.DrawImage(image, rc, null, ImageAlign.Default);
g.DrawString(
"Watermark",
new TextFormat()
{
Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "calibrib.ttf")),
FontSize = Inch,
ForeColor = Color.FromArgb(128, Color.Yellow),
},
rc, TextAlignment.Center, ParagraphAlignment.Center, false);
}
return bmp;
}
}
}