[flexcoders] Working with images of varying proportions

2009-02-23 Thread byte.sensei
I have an app that loads several images into mx:Image tags with 
scaleContent=true and width=160 / height=120. The problem is not all of 
my images have these proportions, and for odd sized images they end up 
being loaded into the upper left hand corner instead of centered in the 
restricting image box.

All I'm trying to do is have a box 160x120 pixels, then load in images 
of various sizes dynamically and have them 1) scale to fit within this 
box, and 2) render centered vertically/horizontally in this box. Is 
there any way I can do this not knowing the actual image sizes (and 
using images of different proportions)?

Thanks!




Re: [flexcoders] Working with images of varying proportions

2009-02-23 Thread Fotis Chatzinikos
For something similar i do the following, you should be able to change it to
do what you want quite easily..:

mx:Image
id=selectedProductImageID
verticalCenter=0
complete=imageLoaded()
source={selectedPhoto}
left=5
/

Now the important bit is the complete=imageLoaded():

and the imageLoaded function:

private function imageLoaded():void
{
if (selectedProductImageID.content.loaderInfo.width =
selectedProductImageID.content.loaderInfo.height)
{
selectedProductImageID.width = 330;
selectedProductImageID.height =
330*selectedProductImageID.content.loaderInfo.height/selectedProductImageID.content.loaderInfo.width
;
}
else
{
selectedProductImageID.height = 330 ;
selectedProductImageID.width =
330*selectedProductImageID.content.loaderInfo.width/selectedProductImageID.content.loaderInfo.height;
}
}

On Mon, Feb 23, 2009 at 9:36 PM, byte.sensei byte.sen...@yahoo.com wrote:

   I have an app that loads several images into mx:Image tags with
 scaleContent=true and width=160 / height=120. The problem is not all of
 my images have these proportions, and for odd sized images they end up
 being loaded into the upper left hand corner instead of centered in the
 restricting image box.

 All I'm trying to do is have a box 160x120 pixels, then load in images
 of various sizes dynamically and have them 1) scale to fit within this
 box, and 2) render centered vertically/horizontally in this box. Is
 there any way I can do this not knowing the actual image sizes (and
 using images of different proportions)?

 Thanks!

  




-- 
Fotis Chatzinikos, Ph.D.
Founder,
Phinnovation
fotis.chatzini...@gmail.com,