如何使缩略图的尺寸为84x84像素?
function createThumbs()
{
_myThumbData = new BitmapData(photodefault.width,photodefault.height,false,0xffffff);
photothumbs.t1.addChild(createBitmap(_myThumbData));
}
function createBitmap(bmd:BitmapData):Bitmap
{
var bitmap:Bitmap = new Bitmap(bmd);
bitmap.smoothing = true;
bitmap.scaleX = bitmap.scaleY = 0.2;
return bitmap;
}
感谢。 乌利
答案 0 :(得分:0)
根据您的评论,您需要调整大小并保持宽高比。 您需要计算原始图像和容器的纵横比,然后根据较大的比例调整容器大小。这就是我的意思:
function createThumbs()
{
_myThumbData = new BitmapData(photodefault.width,photodefault.height,false,0xffffff);
photothumbs.t1.addChild(createBitmap(_myThumbData));
}
function createBitmap(bmd:BitmapData):Bitmap
{
var bitmap:Bitmap = new Bitmap(bmd);
bitmap.smoothing = true;
setSize(bitmap, bmd.width, bmd.height, 84, 84);
return bitmap;
}
function setSize(target:DisplayObject, contentWidth:Number, contentHeight:Number, targetWidth:Number, targetHeight:Number):void {
var w:Number = targetWidth;
var h:Number = targetHeight;
// maintain aspect ratio
var containerRatio:Number = targetWidth / targetHeight;
var imageRatio:Number = contentWidth / contentHeight;
if (containerRatio < imageRatio) h = w / imageRatio;
else w = h * imageRatio;
target.width = w;
target.height = h;
//centre content - this might change based on your setup
target.x = (targetWidth - w) * .5;
target.y = (targetHeight -h) * .5;
}