나는 긴 화면 비율을 유지하면서 이미지 크기를 조정하기 위해이 기능을 사용하고 :
public function constraintResize(iSourceWidth:*, iSourceHeight:*, iTargetWidth:*, iTargetHeight:*, iFitSmallerDimension:*):* {
if (iFitSmallerDimension == undefined) iFitSmallerDimension = false;
if (iTargetWidth == 0 || iTargetHeight == 0) return;
if (iSourceWidth == 0 || iSourceHeight == 0) return;
var newWidth:*;
var newHeight:*;
var targetRatio:*;
var sourceRatio:*;
var output:* = { width:iSourceWidth, height:iSourceHeight };
if (iSourceWidth <= iTargetWidth && iSourceHeight <= iTargetHeight) {
if (iFitSmallerDimension) {
targetRatio = iTargetWidth/iTargetHeight;
sourceRatio = iSourceWidth/iSourceHeight;
if (sourceRatio < targetRatio) {
newHeight = iTargetHeight;
newWidth = newHeight * sourceRatio;
} else {
newWidth = iTargetWidth;
newHeight = newWidth/sourceRatio;
}
output.width = newWidth
output.height = newHeight
}
} else {
targetRatio = iTargetWidth/iTargetHeight
sourceRatio = iSourceWidth/iSourceHeight
if (sourceRatio < targetRatio) {
newHeight = iTargetHeight
newWidth = newHeight * sourceRatio
} else {
newWidth = iTargetWidth
newHeight = newWidth/sourceRatio
}
output.width = newWidth
output.height = newHeight
}
return output
}
기능은 당신에게 target
내 source
에 맞는 이상적인 크기를 줄 것이다. 구성 요소 관리자 wondow에서 진정한
var s:* = constraintResize(loader.contentWidth, loader.contentHeight, yourSquare.width, yourSquare.height);
loader.width = s.width;
loader.height = s.height;
와우! 나는 5 줄의 코드 안에서 그것을 할 수 있다고 생각했다. 감사합니다! 나는 이것을 확실히 시도 할 것이다! –