I'm trying to scale a large bitmap to a 300*200 mesh. The problem is
the bitmap seems to end up a little larger than the intended area. Can
anybody spot why?
Here's the code:
var loadedBitmap:Bitmap =
a_e.currentTarget.content as Bitmap;
loadedBitmap.smoothing = true;
WIDTH = 300;
HEIGHT = 200;
var planeScale : Number = WIDTH / HEIGHT;
var artScale : Number = loadedBitmap.width /
loadedBitmap.height;
var holderWidth : int;
var holderHeight : int;
if ( artScale > planeScale )
{
holderWidth = loadedBitmap.width;
holderHeight = loadedBitmap.width / planeScale;
}
else
{
holderHeight = loadedBitmap.height;
holderWidth = loadedBitmap.height * planeScale;
}
var planeBitmapData : BitmapData = new BitmapData(
holderWidth,
holderHeight, true, 0xFF );
var targetRect : Rectangle = new Rectangle( 0, 0,
loadedBitmap.width, loadedBitmap.height );
var startX : int = ( planeBitmapData.width -
loadedBitmap.width ) /
2;
var startY : int = ( planeBitmapData.height -
loadedBitmap.height ) / 2;
var startPoint : Point = new Point( startX, startY );
planeBitmapData.copyPixels( loadedBitmap.bitmapData,
targetRect,
startPoint );
var artMaterial:BitmapMaterial =
new BitmapMaterial(planeBitmapData, {smooth:true,
debug:false});
for ( var i : int = _shape.faces.length-1; i >= 0; i-- )
{
var currentFace : Face = _shape.faces[i];
currentFace.material = artMaterial;
}