From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DisplayImageFile() does not change dimensions of picture control

Solved!
Go to solution

Hi

 

I'm setting image of a picture control with DisplayImageFile() + setting the control attribute ATTR_FIT_MODE=VAL_SIZE_TO_IMAGE. The image size is bigger then the control size and I want the control to resize to the image size.

 

It works fine except when I query the control dimensions with GetCtrlAttribute(panel,control,ATTR_HEIGHT,&height), I get the original size(before calling DisplayImageFile())...

 

It seems I miss something basic...

 

Environment: LAB Windows CVI 2012 , Windows 7

 

Thanks in advance

Ramy

0 Kudos
Message 1 of 9
(4,823 Views)

Strange enough. On my system it doesn't happen. Can you test the small sample I'm attaching?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 9
(4,807 Views)

Hi

 

Thanks for the help.

I have run your code now and it goes ok! I get the correct dimensions.

 

By quick compare I see only one diference - the picture control mode in your UIR is set to 'size image to control'', while in my UIR it is set to 'size control to image''. However it should not make a diference since both codes set mode programaticaly.

 

I'll try to call your code in a big project where the problem started originaly. I'll call it as a wrapped function...

Strange...I'm confused

0 Kudos
Message 3 of 9
(4,794 Views)

I'm confused too!

Besides it, you should not need to programmatically change that attribute since your control is alread set to autosize.

Let's see if integrating the function in your complete app things work well or if problem remains.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 9
(4,783 Views)

Hi

 

I've try your code inside my project and it doesn't work. Maybe my environment is unstable. I miss SP1(2012). Soon I'll install and see if it change.

 

Secondly, this problem can bypassed, since I always can query the image size and adjust the control...

 

Thanks anyway for the help.

 

Ramy

0 Kudos
Message 5 of 9
(4,707 Views)

What if you simply set the control to "size to picture" in the UIR editor and do not manipulate it's properties in the code?

Additionally, you could try installing 2012SP1 runtime without need to ugrade the IDE.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(4,692 Views)

I already tried it...

 

I'm going to install the whole sw package at once.

0 Kudos
Message 7 of 9
(4,667 Views)
Solution
Accepted by topic author Ramy77

I don't know if you're still having this problem or not, but I just came across this discussion now and wanted to point out that this might happen if your picture control if it's overlapped by another control or if it's hidden altogether (and there might be other similar situations that I can't think of right now).

 

When this happens, then the CVI runtime can't draw the image directly onto the picture. Instead, it schedules an asynchronous action that will redraw that section of the panel from back to front (this is if it's just overlapped, not hidden). It's only during that later action that the image is applied to the control, and it's only then that the control is resized to fit the image. This might appear to be as immediate to the casual observer but, because it's asynchronous, you can't try to get the new size immediately after calling DisplayImageFile, since the image is not yet in the control at that exact moment.

 

Ironically, this only happens if the control was already set to size-to-image at the time that you call DisplayImageFile. If it's not, then the new size is applied when you later change the fit mode programmatically. Whereas if the fit mode was already set to size-to-image, trying to set it programmatically to the same size-to-image value has no effect and nothing happens then.

 

If this is what's happening, one way to work around it would be to call ProcessDrawEvents or ProcessSystemEvents immediately after calling DisplayImageFile. Unless the control or the panel has been explicitly hidden, this will force the drawing action to take place at that time, and you should then be able to get the new control size at any point after that.

 

Luis

Message 8 of 9
(4,524 Views)

Luis, this is the case indeed! My picture control overlap with another picture control.

 

So the asynchronous process you describe might explain the delay in fitting the image.

 

I already tried to call ProcessDrawEvents(), but it did not help.

 

Also updating Run Time Engine to 2012 SP1 didn't help.

 

Meanwhile I worked around the problem: I queried the image size + resized the control accordingly. Not a nice solution but a satisfying one.

 

Thanks for the help.

0 Kudos
Message 9 of 9
(4,462 Views)