AS3按比例调整大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3按比例调整大小相关的知识,希望对你有一定的参考价值。
Usage:<code>
var newDimensions:Object = resize(800,600,320,200);
</code>
This can be adapted to pretty much any language...
/** * resize * Take input diemnsion and return the resulting dimensions using a ratio * @param _w initial width * @param _h initial height * @param _targetW targeted width * @param _targetH targeted height * @param _ratio set the ratio manually instead of automatically detecting it (0) * @return An object containing both resulting dimensions :object.width,object.height */ function resize(_w:Number,_h:Number,_targetW:Number,_targetH:Number,_ratio:Number = 0):Object { var ratio:Number = (_ratio ==0) ? _w / _h : _ratio; var rW:Number = _targetW; var rH:Number = _targetH; if (ratio >= 1) { rH = _targetW / ratio; if (rH > _targetH) { rH = _targetH; rW = rH * ratio; } }else { rW = _targetH * ratio; if (rW > _targetW) { rW = _targetW; rH = rW / ratio; } } var newDimensions:Object = {width:rW,height:rH }; return newDimensions; }
以上是关于AS3按比例调整大小的主要内容,如果未能解决你的问题,请参考以下文章