letter
November 17th, 2009, 10:53 PM
Take a BIG user submited image: say 2848x2136 pixels (I said it was big) and resize it with a Matrix:
private static function resizeBitmapData(bmpSource:BitmapData, setWidth:Number, setHeight:Number):BitmapData {
var scaleWidth:Number=setWidth/bmpSource.width;
var scaleHeight:Number=setHeight/bmpSource.height;
var bmp:BitmapData=new BitmapData(setWidth,setHeight,true,0);
var matrix:Matrix = new Matrix ();
matrix.scale(scaleWidth, scaleHeight);
bmp.draw(bmpSource, matrix);
return bmp;
}
And then add the bitmap to the stage on the next line.... throws the error "can't access a property of a null... blah blah blah"
I get it, it's taking a while for flash to resize my gigantamus image, that's fine and understandable.
Finally to my question: How do I set up a listener (or something else) to make sure the image is actually resized.
I tried firing a method inside my resizer right before the bmp is returned, but that didn't seem to work. Only thing that works is a manual timer to slow things down a bit and that's just messy.
I guess I'm wishing for a bm.draw(bmd).addEventListener(GRAPHICSEVENT.comple te, doneResizing); or something crazy like that. But I can find no such event in the package.
Other ideas for making sure flash is done with bitmap data before adding it to the display list?
private static function resizeBitmapData(bmpSource:BitmapData, setWidth:Number, setHeight:Number):BitmapData {
var scaleWidth:Number=setWidth/bmpSource.width;
var scaleHeight:Number=setHeight/bmpSource.height;
var bmp:BitmapData=new BitmapData(setWidth,setHeight,true,0);
var matrix:Matrix = new Matrix ();
matrix.scale(scaleWidth, scaleHeight);
bmp.draw(bmpSource, matrix);
return bmp;
}
And then add the bitmap to the stage on the next line.... throws the error "can't access a property of a null... blah blah blah"
I get it, it's taking a while for flash to resize my gigantamus image, that's fine and understandable.
Finally to my question: How do I set up a listener (or something else) to make sure the image is actually resized.
I tried firing a method inside my resizer right before the bmp is returned, but that didn't seem to work. Only thing that works is a manual timer to slow things down a bit and that's just messy.
I guess I'm wishing for a bm.draw(bmd).addEventListener(GRAPHICSEVENT.comple te, doneResizing); or something crazy like that. But I can find no such event in the package.
Other ideas for making sure flash is done with bitmap data before adding it to the display list?