Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Nifty  
#1 Posted : Friday, May 26, 2017 8:33:01 AM(UTC)
Nifty

Rank: Advanced Member

Groups: Member
Joined: 10/12/2015(UTC)
Posts: 44

I'm trying to make the case to our company that we should use your SDK instead of NeoDynamic ImageDraw SDK.

But first I need to reproduce the basic text functions found in their library.

Can you someone explain why the text in this example is not at the bottom?
I'm trying to figure out how to mimic their options of:

BottomCenter, BottomLeft, BottomRight,
MiddleCenter, MiddleLeft, MiddleRight
TopCenter, TopLeft, TopRight


Code:

public static byte[] GetText(string txt, int width, int height) {

	using (var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb, RgbColor.Green))
	using (var graphics = bitmap.GetAdvancedGraphics())
	using (var customFont = new CustomFontRegistry()) {
                
		var font = graphics.CreateFont("Courier New", 58);

		var bounded = new BoundedText(txt, font, new System.Drawing.Rectangle(0, 0, width, height));
		bounded.Brush = new SolidBrush(RgbColor.Blue);

		bounded.Alignment = TextAlignment.Bottom;

		graphics.DrawText(bounded);
		return imageToByteArray(bitmap);

	}

}



Fedor  
#2 Posted : Monday, May 29, 2017 3:36:57 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Graphics Mill doesn't support the vertical alignment. Even so, we plan to implement it in the future versions (Aurigma Bug #0022275).

The description of the TextAlignment enumeration misleads. The SDK supports the drawing of vertical text and the TextAlignment.Top and TextAlignment.Bottom values specify the alignment of vertical text only:

align_top.png align_bottom.png

Currently, you can implement the vertical alignment using the GetBlackBox method:

Code:
public static byte[] GetText(string txt, int width, int height)
{

	using (var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb, RgbColor.Green))
	using (var graphics = bitmap.GetAdvancedGraphics())
	using (var customFont = new CustomFontRegistry())
	{

		var font = graphics.CreateFont("Courier New", 58);

		var bounded = new BoundedText(txt, font, new System.Drawing.RectangleF(0, 0, width, height));
		bounded.Brush = new SolidBrush(RgbColor.Blue);

		var blackBox = bounded.GetBlackBox();

		//Bottom
		bounded.Rectangle  = new System.Drawing.RectangleF(0, height - blackBox.Height, width, height);

		//Center
		//bounded.Rectangle = new System.Drawing.RectangleF(0, (height - blackBox.Height) / 2, width, height);

		graphics.DrawText(bounded);

		return imageToByteArray(bitmap);
	}
}


A similar question was discussed here:

Shrinking text and vertical alignment

Edited by user Monday, May 29, 2017 3:40:26 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.