03-30-2010 03:32 PM
Hello all,
I am trying to use either a Picture or Canvas to display an image at fixed aspect ratio (so that it fills the control but only shirnks symmetrically). The Picture control allows one to scale to control but both X and Y are both scaled skewing the image. I would like to be able to use a fixed value in the y axis to size an unknown in the x axis - or vice versa.
Does anyone have a quick and handy way to do this?
03-31-2010 12:42 AM
Hi,
you could try centering the picture on the control, using SetCtrlAttribute (, , ATTR_FIT_MODE, VAL_PICT_CENTER);
If it doesn't help, you always can consider using a graphing program such as Photoshop to adapt the picture to your needs.
In principle, there is a potential problem in your request: if the picture control has a different aspect ratio than the picture, what do you want the control to do? The control can either be scaled to the picture or the picture to the control, nothing in between.
03-31-2010 03:04 AM
An alternative to using an external application can be a tricky use of native picture control
:
1. Create a hidden picture control with fit mode set as VAL_SIZE_TO_IMAGE
2. Load the picture on the control and get control dimensions
3. Set the control as VAL_SIZE_TO_PICTURE; calculate the new dimensions to maintain the correct H/W proportion and resize the control
4. Get the scaled picture with GetCtrlDisplayBitmap
5. Load the bitmap into the visible picture control set as VAL_PICT_CENTER
6. Discard the hidden picture control and the bitmap
you'll have the picture proportionally sized to the maximum dimension compatible with the destination picture control, centered into it.
If you prefere, you can do the whole procedure into one control only: if you don't update the screen in the meanwhile the user will know nothing of it. I'm not sure, but in this case it is possible that hiding the picture control during these operations makes the whole thing faster.
03-31-2010 09:42 AM
Thanks Guys,
I was working toward something similar to Robert's solution but want to make sure there wasn't a cute trick I was missing.
The probelm is that this is for a charity fishing tourney and the input picture sizes vary wildly contestant to contestant - and are mostly too big for the given screen size. I will work on the idea of getting the H and W pixel count and replicating the aspect in the control. I will see if VAL_SIZE_TO_IMAGE will work if the control now goes offscreen. In the end I may have to consider how to implement zoom features as well but one step at a time.
I will mark this solved as soon as I get some time to doublecheck the subtle aspects.
03-31-2010 05:24 PM
When you spoke about zooming I happened to think to using the canvas control instead of the picture one, so I made up the simple project attached (starting from canvas.prj example that ships with CVI) that handles loading pictures from files and zoming them in and out. Image proportions are preserved both in loading and zooming.
It may help you a little in designing your own solution.