LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Horizontally center a 2D picture in an image control

Solved!
Go to solution

Hi all,

 

I'm trying to horizontally center a picture into an image control. Unfortunately, this is not working so far...

I can't change the image control size as I'm using different pictures which have not the same dimensions.

There is a lot of posts talking about pictures in LabView, but I didn't find any concrete answer for my specific issue.

 

Here is a screenshot of my current try.

 

Gub156_0-1578467922339.png

 

Could someone help me?

 

Thank you in advance for your precious help!

 

Julien

0 Kudos
Message 1 of 9
(3,774 Views)

Hi Gub,

 

it would really help when you would attach your VI instead of a simple image of a part of your block diagram…

 


@Gub156 wrote:

I'm trying to horizontally center a picture into an image control. Unfortunately, this is not working so far...


What is "not working"? (That's not an error message from LabVIEW…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(3,762 Views)

Hi GerdW,

 

Thank you for your answer. Attached, you'll find the related VI.

Also here are more details about my issue: I can't figure out how the horizontal alignment works. Currently, I have two different pictures and one is centering correctly. The second one is absolutely not centered (see pictures).

 

Hope that my comments help to understand my issue.

 

Thank you in advance.

 

Julien

Download All
0 Kudos
Message 3 of 9
(3,752 Views)
Solution
Accepted by topic author Gub156

I'd keep the origin at 0,0. That's usually more intuitive:

Center Image.PNG

 

The horizontal center to draw the image (with it's original W\H!), is ( control.W - img.H*scale ) / 2 / scale.

Message 4 of 9
(3,729 Views)

BTW. The build in function "Get File Extension.vi" returns the file extension.

0 Kudos
Message 5 of 9
(3,726 Views)

Hi wiebe,

 

Thank you for your answer. I'm actually running LabView 2017 and I can't run your VI. Is this "Get File Extension" VI new? I never saw it?

Anyway, I'll try your solution in my VI and post my answer later.

 

Regards,

 

 

Julien

0 Kudos
Message 6 of 9
(3,723 Views)

Hi Gub,

 


@Gub156 wrote:

I'm actually running LabView 2017 and I can't run your VI. Is this "Get File Extension" VI new? I never saw it?


GetFileExtension is also available in LV2017. As it's a file-related function you should look into the file functions palette (or use Quickdrop)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 9
(3,721 Views)

Note that x2^-1 is simply a x/2 or x*.5.

 

x2^-1 is beneficial when scaling integers, because the output is an integer.

 

In your example, the input was an integer, before I changed it to a dbl.

0 Kudos
Message 8 of 9
(3,717 Views)

Thank you for your solution! It works perfectly!

 

I hope this will help other users as well.

 

Regards,

 

 

Julien

0 Kudos
Message 9 of 9
(3,711 Views)