ActionScripts3 实现视频根据视频实际尺寸截图

本文详细解析了一段使用Flash进行视频截图的代码实现过程。通过调整BitmapData的大小以匹配视频的实际宽度和高度,利用Matrix进行坐标转换,最终将截图保存为PNG格式。代码涵盖了错误处理和文件保存的具体细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接上实现代码代码

	import com.adobe.images.PNGEncoder;
	import flash.net.FileReference;
	import flash.geom.Matrix;
	import flash.display.BitmapData;

		public function onCapture():*
		{
			var m:Matrix;

			trace("onCapture-Width:"+this.video.width+",Height:"+this.video.height+",Video Width:"+this.video.videoWidth+",Video Height:"+this.video.videoHeight);
			try
			{
				//固定了截图尺寸,不知道为什么无法根据this.video.videoWidth, this.video.videoHeight截图
				//var bmpd:* = new BitmapData(352, 288);
				//var bmpd:* = new BitmapData(704, 576);
				var bmpd = new flash.display.BitmapData(this.video.videoWidth, this.video.videoHeight);
				m = new Matrix(video.videoWidth/320,0,0,video.videoHeight/240);

				
				bmpd.draw(this.video,m,null,null,null,true);
			}
			catch (e:Error)
			{
				//ExternalInterface.call("onVideoMsg", "" + 0 + "", "PicSave-error" + e.message);
				return;
			}
			var imgByteArray:* = PNGEncoder.encode(bmpd);
			var FileRefe:* = new FileReference();
			var date:* = new Date();
			var info:*;
			
			var s:* = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + "-" + date.getMinutes() + "-" + date.getSeconds() + ".png";
			FileRefe.save(imgByteArray, s);
			return;
		}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值