PDA

View Full Version : Load image into specific dimensions?



Katie Lee
November 15th, 2008, 06:38 PM
How do I enable an image to be loaded from a server into specific dimensions at runtime?

This is what I've got, but it's just loading it in the top right corner.



uploadDisplay.load(new URLRequest(newURLString));
uploadDisplay.contentLoaderInfo.addEventListener(E vent.COMPLETE, contentComplete);
}

function contentComplete(event:Event):void{
trace (uploadDisplay.content);
test_txt.appendText(" in contentComplete: " + uploadDisplay.width);


var w:Number = uploadDisplay.width;
var h:Number = uploadDisplay.height;
var bitmapDataA:BitmapData = new BitmapData(w/1, w/1);

bitmapDataA.draw(uploadDisplay, new Matrix(), null, null, new Rectangle(0,0,w/1,w/1));
var bitmapA:Bitmap = new Bitmap(bitmapDataA);
addChild(bitmapA);
}

HMPoweredMan
November 15th, 2008, 06:51 PM
var bitmapDataA:BitmapData = new BitmapData(desiredWidth, desiredHeight);

Im pretty sure, but not positive that this is all you have to do.

senocular
November 15th, 2008, 07:13 PM
Do you want to crop, or scale? Do you care about the bitmap pixels being accurately scaled or for it to just look the right size?

If you just want it to look the right size, just set the loader's width and height to what you want when the image loads. If you want the pixels to be scaled to that size and have a bitmap data of that size, then, if cropping, just make a new bitmap data and draw as you would regularly. If scaling you'd need to apply a matrix which has been scaled.

Katie Lee
November 15th, 2008, 09:16 PM
Hi Senocular :)

The image needs to be accurately scaled. I'm a bit confused by your answer.

The user will upload a picture of themselves, scale and rotate it to fit their face inside a head shape. Then the program will hopefully cut it out and stick it into an animation in the next scene.