LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Draw text as an image to fit a box?

Solved!
Go to solution
Solution
Accepted by topic author datatechNDT

This is the final VI that I`ve created. It takes a string as an input and desired width in pixels and the output is the 2d drawing of the string and the font size.

Message 11 of 23
(1,497 Views)

Nice, I smell a coding challenge coming on...

 

Write a VI that draws a 2D picture with a size that approaches a given XY size, but does not go over, which contains the text (multi-line) that is provided.  Faster processing time the better.  The code you provided is already tons faster than what I came up.  I'll have to look into making it work in the vertical size as well.

0 Kudos
Message 12 of 23
(1,486 Views)

Already did, but probably not in the right place (and I'm not sure how I got there, either).  https://forums.ni.com/t5/Example-Program-Drafts/Auto-size-to-Text-Horizontal-for-Strings-and-Paths/t....

 

Bob Schor

0 Kudos
Message 13 of 23
(1,470 Views)

Sorry Bob but that isn't really what I'm talking about, it is more like the reverse.  I don't want to make a control fit to text, I want to make the text fit a control, or rather the text to fit a size.  I did modify datatech's code to fit for vertical but had a few issues and got side tracked.

0 Kudos
Message 14 of 23
(1,468 Views)

@Hooovahh wrote:

Sorry Bob but that isn't really what I'm talking about, it is more like the reverse.  I don't want to make a control fit to text, I want to make the text fit a control, or rather the text to fit a size.  I did modify datatech's code to fit for vertical but had a few issues and got side tracked.


https://en.wikipedia.org/wiki/Automatic_label_placement

https://www.sciencedirect.com/science/article/pii/S0925772196000077

 

interesting!

0 Kudos
Message 15 of 23
(1,448 Views)

We use this.

"If you weren't supposed to push it, it wouldn't be a button."
Message 16 of 23
(1,422 Views)

@paul_cardinale wrote:

We use this.


Interesting code.  I read the Documentation to figure out what this does, looked at the code, made some guesses and tried various numbers, but still can't say I have any real clue ...  

  • What are the meaning(s) of the Input parameters?
  • What are the meaning(s) of the Output values?
  • What, specifically, does "Text.Size" mean?  (I did notice that leaving it at the default value of 0, 0 produced only "..." in Text Out).
  • I was able to get "asdfdsfa" in Text Out.  Curiously, the output Font Size was 20, but the Font Size of Text Out was 13.  The Font Size of Text In was 15, if that matters.  Note that "asdfdsfa" did not fill the Text Out box.

Bob Schor

0 Kudos
Message 17 of 23
(1,411 Views)

"asdfdsfa" can be rendered in a rectangle with width 100 px height 20 px

with the Font-Size 20 (e.g. Arial)

the actual rectangle for this setting has a width 62 and height 19

 

observation: the Font Size and the rectangular's height in px are mostly identical, if not, those two numbers vary in a range +1 or -1

 

change the width to 50 px - now it is not possible to render "asdfdsfa" with Font Size 20 in a rectangle with width 50 px height 20 px

 

Paul's vi calculates a  Font-Size = 16 to render the text "asdfdsfa" in a rectangle with width 50 px height 20 px.

The actual rectangle has width 49 height 16

 

 

Download All
0 Kudos
Message 18 of 23
(1,398 Views)

Sorry about that.  I shouldn't have just sent out an old VI without looking at it closely.

'Font Size' in is the preferred (maximum) font size.

'Text.Size' is the size of the box you want the text to fit in.

'Font Size' out is the size that will fit in the box.

'Text Out' is either 'Text In' or "..." depending on whether the text can be made to fit in the box.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 19 of 23
(1,377 Views)

Just dropping in here.

 

I am trying to write Text into a series of images (Vision module - IMAQ Overlay Text VI) and am running into a similiar problem as the images of one image series got a fixed width, which i do not want to change, but the next series might have another fixed width.

 

Could you downgrade your VI's to 2017? Still not up to date here 😉

0 Kudos
Message 20 of 23
(1,143 Views)