LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

resize graphics to fit picture control

Can anyone tell me how to programatically (in LV 5.1.1) scale any jpg graphics
file to fit in a fixed size picture control. Example: An entire 1024 x 768
resolution image from a file would display in a picture control with its
'Draw area size' attribute set to 480 x 320. All examples regarding sizing
that I have been able to find to date resize the control to the size of the
graphics. This is the opposite effect of what I want to do and not a viable
option for large .jpg's and limited screen real estate. Am I missing something
obvious here?

Thanx in advance...
0 Kudos
Message 1 of 2
(3,123 Views)
"Ian R. Nelson" wrote in message
news:<39b9683c@newsgroups.ni.com>...
>
> Can anyone tell me how to programatically (in LV 5.1.1) scale any jpg
graphics
> file to fit in a fixed size picture control. Example: An entire 1024 x
768
> resolution image from a file would display in a picture control with its
> 'Draw area size' attribute set to 480 x 320. All examples regarding
sizing
> that I have been able to find to date resize the control to the size of
the
> graphics. This is the opposite effect of what I want to do and not a
viable
> option for large .jpg's and limited screen real estate. Am I missing
something
> obvious here?

I wrote a small VI to do that function this summer during an internship.

I always work in terms of a 2D array. I ended up created nested for-loops
which I think is the fastest possible route. I determined the input
picture's height and width and used a front-panel control (variable) for the
output picture's height and width. This could be easily replaced with a zoom
factor instead too.

I took some ratios of input to output and determined what stepsize on the
original picture would reflect each output pixel. For example, shrinking
would have >1 pixel steps, growing would have <1 pixel steps.

Then I thought really hard and came up with a formula which would give me a
weighted Z value for the float(X) and float(Y) we're at thanks to the
stepsize in the current loop iteration. You have to do this because you only
actually know the value at integer pixels. I think that I took a floor and
ceil and used the surrounding four points to calculte this weighting. For a
more sophisticated algorithm try more and further-away surrounding points.
For a lazier solution just round and use the closest integer.

One warning. Watch the colormap. Unless you use a linear colormap this ain't
gonna work.

That will scale your pictures. Somebody told me about a better method
involving matrixes but I don't know enough linear algebra yet. I would love
to see a comparison between my method and using some sort of transfer-matrix
in terms of performance. Rotation is a similar algorithm, just a simple
coordinate transform using trig.

It worked... slow, but it worked. With a big image this can take several
hundred milliseconds. It is very far from realtime.

-joey
0 Kudos
Message 2 of 2
(3,123 Views)