Watermark.cs
//
// このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
// © 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
{
// このサンプルは、画像にテキストのウォーターマークを追加する方法を示しています。
// 画像はネイティブ解像度でGcBitmapにレンダリングされ、ウォーターマークテキストは半透明の色でその上に描画されます。
// ウォーターマークが追加されたビットマップは、サポートされている任意の画像形式で保存できます。
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", "FreeSansBold.ttf")),
FontSize = Inch,
ForeColor = Color.FromArgb(128, Color.Yellow),
},
rc, TextAlignment.Center, ParagraphAlignment.Center, false);
}
// 画像ファイルを保存します。
return bmp;
}
}
}