Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
noahnu
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Autosize an image?

[ Edited ]

Hello, currently I am using the following code to add an image to the screen.

 

 

var bmp:BitmapData = new BitmapData(200,200);
bmp.draw((e.target as LoaderInfo).content); //error
var newImg:Image = new Image();
newImg.buttonMode = true;
newImg.graphics.beginBitmapFill(bmp);
newImg.graphics.drawRect(0,0,200,200);
newImg.graphics.endFill();
this.addChild(newImg);

 

 

The LoaderInfo is being retrieved from a File.BrowseforOpen.

 

Right now if the image is larger than 200x200 then parts of it are cut off. If it is smaller than 200x200 than the left over space is white. Instead of setting the image size to be 200x200 is there a way to retrieve the size of the image being loaded with the File.BrowseforOpen and use those dimensions? If the dimensions are bigger than the blackberry playbook screen than scale it down?

 

Also by using 'graphics' I am not able to use any of the blendMode effects of the image object. How would I use newImg.setImage() to set the BitmapData of bmp? When I tried newImg.setImage(bmp); an image was not visible. *Note that when I tested it with .setImage I set the size of the image object after the image was finished loading - the Event.Complete event.

From,
Noah NU
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Autosize an image?

[ Edited ]

hey noah,

 

how does your loader look? and assuming that you are retrieving the clicked object's info and then loading it? usually when i use the loader class after the object is done loading, i can see its width, height, etc. most likely why the image isnt showing up is you arent waiting long enough till the image is fully loaded and then set the image to your image object. so i would set up a Event.COMPLETE on the Loader object and then set the image and heights and widths after that.

 

Edit: Here is a link to a thread that might be able to help you out a little:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/qnx-ui-display-Image-sizing-issue...

 

good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Autosize an image?

So you have a targetSize you want to get to, and a bitmap that is any size, you want to scale to fit without any cropping?

 

This'll do it:

var targetWidth:int = 1024;

var targetHeight:int = 600;

var bitmapWidth:int = bitmap.bitmapData.width;

var bitmapHeight:int = bitmap.bitmapData.height;

var scale:Number = Math.min(targetWidth/bitmapWidth, targetHeight/bitmapHeight);

 

bitmap.scaleX = bitmap.scaleY = scale;

 

I usually just use rectangles:

 

var target:Rectangle = new Rectangle(0, 0, 1024, 600);

var bitmapSize:Rectangle = new Rectangle(0, 0,bitmap.bitmapData.width, bitmap.bitmapData.height);

bitmap.scaleX = bitmap.scaleY = Math.min(target.width/bitmapSize.width, target.height/bitmapSize.height);

 

Please use plain text.
Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Autosize an image?

Oh, and you're loading your bitmap the hard way, user the Loader() class, and then:

 

var bitmap:Bitmap = loader.content as Bitmap;

 

Then you can get the original size by looking at the .bitmapData

Please use plain text.
Developer
noahnu
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Autosize an image?

So I go straight to a Bitmap instead of BitmapData?

From,
Noah NU
Please use plain text.