Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
The GetBlackBox method returns an exact size of the text, i.e. it interprets the text as vector data. That's why the coordinates have float type - the black box may be located “between” pixels, etc. Unlike it, the shadow effect is applied to the raster, after the vector data is rasterized. So we don’t know the exact size of a shadow before the image is flattened. That's why we ignore effects when calculating the blackbox. However, you can still estimate the text size with the shadow effect (+/- couple pixels). The following code should give you an idea how to do it: Code:using System;
using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.AdvancedDrawing.Art;
using Aurigma.GraphicsMill.AdvancedDrawing.Effects;
using Aurigma.GraphicsMill.AdvancedDrawing;
namespace Forum_13972
{
class Program
{
static void Main(string[] args)
{
var text = "Hello World!";
var intensity = 0.2f;
using (var bitmap = new Bitmap(600, 200, PixelFormat.Format24bppRgb, new RgbColor(0xff, 0xff, 0xff, 0xff)))
using (var graphics = bitmap.GetAdvancedGraphics())
{
var font = graphics.CreateFont("Tahoma", 80);
var brush = new SolidBrush(RgbColor.Blue);
var artText = new BridgeText(text, font, brush, 0, 0, intensity);
var shadowSize = 5f;
var shadowOffsetX = 20f;
var shadowOffsetY = 15f;
artText.Effect = new Shadow(RgbColor.Red, shadowSize, shadowOffsetX, shadowOffsetY, 1);
artText.Center = new System.Drawing.PointF(300f, 100f);
graphics.DrawText(artText);
var textBlackBox = artText.GetBlackBox();
graphics.DrawRectangle(new Pen(RgbColor.Black, 1f), textBlackBox);
var shadowBlackBox = new System.Drawing.RectangleF(
textBlackBox.X - shadowSize + shadowOffsetX,
textBlackBox.Y - shadowSize + shadowOffsetY,
textBlackBox.Width + shadowSize * 2,
textBlackBox.Height + shadowSize * 2);
graphics.DrawRectangle(new Pen(RgbColor.Red, 1f), shadowBlackBox);
var unionBlackbox = System.Drawing.RectangleF.Union(textBlackBox, shadowBlackBox);
graphics.DrawRectangle(new Pen(RgbColor.Green, 1f), unionBlackbox);
bitmap.Save("../../../ArtText.png");
}
}
}
}
Fedor attached the following image(s): |
Best regards, Fedor Skvortsov
|