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

Notification

Icon
Error

Options
Go to last post Go to first unread
NormanL  
#1 Posted : Thursday, January 24, 2013 8:25:01 AM(UTC)
NormanL

Rank: Advanced Member

Groups: Member
Joined: 4/26/2012(UTC)
Posts: 36

Thanks: 6 times
Hi,

I have a requirement whereby I have to be able to store the coordinates of some user defined text on an image. This is so the image with the text can be replicated outside of the [Aurigma] application on which it was generated (e.g. where there is no concept of a bounding box). The coordinates I need to store are the centerpoint of the text relative to the centerpoint of the image. I can retrieve the bounds of the TextVObject (or ImageVObject in the case of outlined text) and can derive its centerpoint but this does not equate to the centerpoint of the actual text within the box(?). I need the centerpoint of the actual text as this will remove the reliance on the bounding box that is particular to Aurigma. I've also noted the size of the bounding box can vary depending on the font being used i.e. there is more whitespace around some fonts than others. I've attached a couple of images to illustrate what I mean.

Both images are of the same TextVObject with its bounding box. The TextVObject has its Alignment property set to TextAlignment.Center. The centerpoint of the image is marked with an orange dot on both and is at position (166, 72). You may have to zoom in using an image editor to see what I mean.

If I take the centerpoint of the text using the bounding box (please see centerbox.png) the centerpoint of the text would be at (160, 74), whereas if I take the centerpoint as being the from the bounds of the actual text the centerpoint of the text would be at (156, 76) as illustrated by the green dots. Is there a way to determine the centerpoint of the actual text? In order to draw outlined text I've written the text to an image so that might be the may to go but I haven't managed to have a fixed amount of whitespace around it.

Any help would be appreciated.

Thanks,

Norman

Edited by user Thursday, January 24, 2013 10:19:40 AM(UTC)  | Reason: Not specified

NormanL attached the following image(s):
centerbox.png
centertext.png
vitaly  
#2 Posted : Friday, January 25, 2013 1:09:26 AM(UTC)
vitaly

Rank: Advanced Member

Groups:
Joined: 12/19/2012(UTC)
Posts: 164

Was thanked: 8 time(s) in 8 post(s)
Hello Norman,

You can find solution youself here: http://imaging.aurigma.c...gm/MeasuringTextSize.htm

I have written example for you:
Code:

             // Create Bitmap object.
            Aurigma.GraphicsMill.Bitmap bitmap =
                new Aurigma.GraphicsMill.Bitmap(250, 40, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

            bitmap.Unit = Aurigma.GraphicsMill.Unit.Point;

            Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

            // Fill background.
            graphics.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush(
                Aurigma.GraphicsMill.RgbColor.White), 0, 0, bitmap.Width, bitmap.Height);

            // Adjust font settings.
            Aurigma.GraphicsMill.Drawing.Font timesFont =
                new Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 10, false, true);

            string text = "Single-line text...";

            // Measure the text size.
            System.Drawing.SizeF size = timesFont.MeasureString(text);

            Aurigma.GraphicsMill.Drawing.SolidBrush blackBrush =
                new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

            graphics.DrawString(text, timesFont, blackBrush, 0, 0);

            Aurigma.GraphicsMill.Drawing.SolidBrush redBrush =
                new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Red);

            Aurigma.GraphicsMill.Drawing.Font tahomaFont = new
                Aurigma.GraphicsMill.Drawing.Font("Tahoma", 12);

            
            // centerpoint coordinates
            int centerX = (int)(size.Width / 2);
            int centerY = (int)(size.Height / 2);


            // to output
            text = "Width: " + size.Width.ToString() + " center X: " + centerX.ToString();
            graphics.DrawString(text, tahomaFont, redBrush, size.Width + 50, 0);

            text = "Height: " + size.Height.ToString() + " center Y: " + centerY.ToString();
            graphics.DrawString(text, tahomaFont, redBrush, size.Width + 50, 20);


I think this is exactly what you need. I hope it helps.

Best regards,
Vitaly Kustov
Aurigma Technical Support
Best regards,
Vitaly Kustov
Aurigma Technical Support
NormanL  
#3 Posted : Monday, January 28, 2013 3:24:33 AM(UTC)
NormanL

Rank: Advanced Member

Groups: Member
Joined: 4/26/2012(UTC)
Posts: 36

Thanks: 6 times
Hi,

Thanks for the pointer. Why is it if I use System.Drawing that the output [i.e. size] differs from when I use Aurigma.GraphicsMill. Both should be size 50pt:

Code:

Dim bmp As Bitmap = New System.Drawing.Bitmap(1000, 300, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim graphics As System.Drawing.Graphics = graphics.FromImage(bmp)
graphics.FillRectangle(New System.Drawing.SolidBrush(System.Drawing.Color.White), 0, 0, bmp.Width, bmp.Height)
Dim font As New System.Drawing.Font("Times New Roman", 50, FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
Dim text As String = "Hello World"
Dim size As System.Drawing.SizeF = graphics.MeasureString(text, font)
Dim blackBrush As System.Drawing.SolidBrush = New System.Drawing.SolidBrush(Color.Black)
graphics.DrawString(text, font, blackBrush, 0, 0)
bmp.Save("C:\Times New Roman System.bmp")


Code:

Dim bmp As Aurigma.GraphicsMill.Bitmap = New Aurigma.GraphicsMill.Bitmap(1000, 300, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)
bmp.Unit = Aurigma.GraphicsMill.Unit.Point
bmp.HorizontalResolution = 96
bmp.VerticalResolution = 96
Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bmp.GetGdiGraphics()
graphics.FillRectangle(New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.White), 0, 0, bmp.Width, bmp.Height)
Dim font As Aurigma.GraphicsMill.Drawing.Font = New Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 50, False, False)
font.Unit = Aurigma.GraphicsMill.Unit.Point
Dim text As String = "Hello World"
Dim size As System.Drawing.SizeF = font.MeasureString(text)
Dim blackBrush As Aurigma.GraphicsMill.Drawing.SolidBrush = New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black)
graphics.DrawString(text, font, blackBrush, 0, 0)
bmp.Save("C:\Times New Roman Aurigma.bmp")


I note if I change the line:

Code:
Dim font As New System.Drawing.Font("Times New Roman", 50, FontStyle.Regular, System.Drawing.GraphicsUnit.Point)


to

Code:
Dim font As New System.Drawing.Font("Times New Roman", 50, FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel)


the font sizes are the same. How do I specify point size in Aurigma?

Thanks

Edited by user Monday, January 28, 2013 4:07:24 AM(UTC)  | Reason: Not specified

vitaly  
#4 Posted : Monday, January 28, 2013 4:34:20 AM(UTC)
vitaly

Rank: Advanced Member

Groups:
Joined: 12/19/2012(UTC)
Posts: 164

Was thanked: 8 time(s) in 8 post(s)
Hello,

I have tried to test you code locally. I got identical images. Probably you got different images because you use non-standard screen resolution.

I attached images which I got.

Best regards,
Vitaly Kustov
Aurigma Technical Support
vitaly attached the following image(s):
Times New Roman Aurigma.bmp
Times New Roman System.bmp
Best regards,
Vitaly Kustov
Aurigma Technical Support
NormanL  
#5 Posted : Monday, January 28, 2013 5:06:40 AM(UTC)
NormanL

Rank: Advanced Member

Groups: Member
Joined: 4/26/2012(UTC)
Posts: 36

Thanks: 6 times
Hi Vitaly,

Why would they be different though? I'm using a screen resolution of 1920x1080. If I go to http://www.hpaa.com/css1/fontsizes.asp#samples the font sizes are displayed as they are using System drawing methods. How can I be sure that the font sizes are consistent across all resolutions. If I write a piece of text to a image I'd expect it to always be the same size? I get the output as attached (please ignore the font, I selected a different one - Forte - but the result is the same as using Times).

Thanks

Edited by user Monday, January 28, 2013 7:24:26 AM(UTC)  | Reason: Not specified

NormanL attached the following image(s):
Forte.bmp
Forte_A.bmp
vitaly  
#6 Posted : Tuesday, January 29, 2013 12:52:30 AM(UTC)
vitaly

Rank: Advanced Member

Groups:
Joined: 12/19/2012(UTC)
Posts: 164

Was thanked: 8 time(s) in 8 post(s)
Hello,

Quote:
How do I specify point size in Aurigma?

You can use UnitConverter class (http://www.aurigma.com/docs/gm/AllMembers_T_Aurigma_GraphicsMill_UnitConverter.htm)

Best regards,
Vitaly Kustov
Aurigma Technical Support
Best regards,
Vitaly Kustov
Aurigma Technical Support
NormanL  
#7 Posted : Tuesday, January 29, 2013 1:12:00 AM(UTC)
NormanL

Rank: Advanced Member

Groups: Member
Joined: 4/26/2012(UTC)
Posts: 36

Thanks: 6 times
Hi Vitaly,

Please can you explain how UnitConverter relates to the issue I was having?

Please note I am simply creating an image and writing it out to file - why is the text size different when both methods are using points?

Thanks
vitaly  
#8 Posted : Tuesday, January 29, 2013 3:27:58 AM(UTC)
vitaly

Rank: Advanced Member

Groups:
Joined: 12/19/2012(UTC)
Posts: 164

Was thanked: 8 time(s) in 8 post(s)
NormanL,

Quote:
Please can you explain how UnitConverter relates to the issue I was having?


Please change the line:
Code:
Dim font As Aurigma.GraphicsMill.Drawing.Font = New Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 50, False, False)

to:
Code:
Dim font As Aurigma.GraphicsMill.Drawing.Font = New Aurigma.GraphicsMill.Drawing.Font("Times New Roman", UnitConverter.ConvertUnitsToPixels(96, 50, Unit.Point), False, False)


And you will get an image with the same text size.

Best regards,
Vitaly Kustov
Aurigma Technical Support
Best regards,
Vitaly Kustov
Aurigma Technical Support
NormanL  
#9 Posted : Wednesday, January 30, 2013 9:29:18 AM(UTC)
NormanL

Rank: Advanced Member

Groups: Member
Joined: 4/26/2012(UTC)
Posts: 36

Thanks: 6 times
Hi Vitaly,

Thanks - I thought by setting the bitmap resolution the font would adopt the same resolution. If I change the System.Drawing.Bitmap resolution the font size changes automatically.
Users browsing this topic
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.