02-04-2011 11:15 PM - edited 02-04-2011 11:44 PM
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.
02-05-2011 02:51 AM - edited 02-05-2011 03:02 AM
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:
good luck!
02-05-2011 11:17 AM
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.heigh
bitmap.scaleX = bitmap.scaleY = Math.min(target.width/bitmapSize.width, target.height/bitmapSize.height);
02-05-2011 11:24 AM
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
02-05-2011 12:18 PM
So I go straight to a Bitmap instead of BitmapData?