Watermark.cs
//
// This code is part of GrapeCity Documents for Imaging samples.
// Copyright (c) GrapeCity, 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;

namespace GcImagingWeb.Samples
{
    // 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(int pixelWidth = 1024, int pixelHeight = 1024, bool opaque = true, float dpiX = 96, float dpiY = 96)
        {
            var Inch = dpiX;
            var bmp = new GcBitmap(pixelWidth, pixelHeight, opaque, dpiX, dpiY);
            using (var g = bmp.CreateGraphics(Color.LightGray))
            using (var image = Image.FromFile(Path.Combine("Resources", "Images", "reds.jpg")))
            {
                var rc = new RectangleF((pixelWidth - image.Width) / 2, (pixelHeight - image.Height) / 2, image.Width, image.Height);
                g.DrawImage(image, rc, null, ImageAlign.Default);

                g.DrawString(
                    "Watermark",
                    new TextFormat()
                    {
                        Font = Font.FromFile(Path.Combine("Resources", "Fonts", "calibrib.ttf")),
                        FontSize = Inch,
                        ForeColor = Color.FromArgb(128, Color.Yellow),

                    },
                    rc, TextAlignment.Center, ParagraphAlignment.Center, false);
            }
            return bmp;
        }
    }
}