如何在flash中按比例缩放不同大小的视频?
所以我创建了我的vdeo播放器,但我在处理不同大小的视频时遇到了问题。如何按比例适当缩放视频 我从元数据对象获取原始宽度和高度:如何在flash中按比例缩放不同大小的视频?,flash,actionscript-3,video,scaling,Flash,Actionscript 3,Video,Scaling,所以我创建了我的vdeo播放器,但我在处理不同大小的视频时遇到了问题。如何按比例适当缩放视频 我从元数据对象获取原始宽度和高度: private function onMetaData(newMeta:Object):void { _height = newMeta.height; _width = newMeta.width; scaleProportional();
private function onMetaData(newMeta:Object):void
{
_height = newMeta.height;
_width = newMeta.width;
scaleProportional();
}
您可以这样做:
// set video dimensions to match player;
video.width = player.width;
video.height = player.height;
// choose the larger scale property and match the other to it;
( video.scaleX < video.scaleY ) ? video.scaleY = video.scaleX : video.scaleX = video.scaleY;
// maybe center video in player ...
//设置视频尺寸以匹配播放器;
video.width=player.width;
video.height=player.height;
//选择较大比例的属性并将另一个与之匹配;
(video.scaleX
1。比例因子
一种方法是计算比例因子。它等于宽度除以高度:
var proportions: Number = video.width / video.height;
您可以将该系数应用于设置视频的任何新宽度或高度:
function scaleProportionalByWidth ( newWidth:Number ) : void {
video.width = newWidth;
video.height = newWidth / proportions;
}
function scaleProportionalByHeight ( newHeight : Number ) : void {
video.height = newHeight;
video.width = newHeight * proportions;
}
2.比例因子
另一种方法是找出缩放视频的因子,然后设置scaleX
和scaleY
,而不是width
和height
:
function scaleProportionalByWidth ( newWidth : Number ) : void {
scaleProportional ( newWidth, video.width );
}
function scaleProportionalByHeight ( newHeight : Number ) : void {
scaleProportional ( newHeight, video.height );
}
function scaleProportional ( newValue:Number, oldValue : Number ) : void {
var scale:Number = newValue / oldValue;
video.scaleX *= scale;
video.scaleY *= scale;
}
3.比例显示对象类
您也可以使用第2部分中的方法。要通过覆盖宽度
、高度
、scaleX
和scaleY
的设置器来创建任何显示对象
的比例子类,以使所有缩放成比例:
// works for Sprite, MovieClip...
public class ProportionalDisplayObject extends DisplayObject {
override public function set width ( width:Number ) : void {
scaleX = width / super.width;
}
override public function set height ( height:Number ) : void {
scaleY = height / super.height;
}
override public function set scaleX ( scaleX : Number ) : void {
super.scaleX = super.scaleY = scaleX;
}
override public function set scaleY ( scaleY : Number ) : void {
super.scaleY = super.scaleX = scaleY;
}
}