views:

449

answers:

1

I've loaded a JPG with dimensions 3264x2448 into a Sprite. How can I resize it proprtionally to allow meto draw the Sprite into a BitmapData object (which in CS3/Flash Player 9 is limited to 2880 height or width). My goal is to use the Soulwire [DisplayUtils][1] to create a thumbnail. Here is the code that works fine with other, smaller, Sprites:

var bmpd:BitmapData = new BitmapData(jpgSprite.width, jpgSprite.height, true, 0x00FFFFFF);
bmpd.draw( jpgSprite );

var thumb:Bitmap = DisplayUtils.createThumb( bmpd, 100, 100, Alignment.MIDDLE, true);
addChild( thumb );

thanks for your suggestions.

+1  A: 

I guess using a matrix to scale it down might do the trick. I haven't tested the code though.

var w:Number = 3264;
var h:Number = 2448;
var scale:Number = w / 2880;
var bmpd:BitmapData = new BitmapData(2880, h / scale, true, 0x00FFFFFF);
var matrix:Matrix = new Matrix();
matrix.createBox(scale, scale)
bmpd.draw(jpgSprite, matrix);
Amarghosh
Worked like a charm, thanks! Here's my generalized version: var w:Number = jpgSprite.width; var h:Number = jpgSprite.height; var scale:Number = 1; if ( h>2880 || w>2880 ) { scale = ( h > w ) ? h / 2880 : w / 2880; } var bmpd:BitmapData = new BitmapData(w / scale, h / scale, true, 0x00FFFFFF); var xform:Matrix = new Matrix(); xform.createBox( scale, scale ); bmpd.draw( jpgSprite, xform );
bob quinn