[AS3]as3.0中视频分切BitmapData.draw使用代码示例
[AS3]as3.0中视频分切BitmapData.draw使用代码示例
[AS3]as3.0中视频分切BitmapData.draw使用代码示例
- package {
- import com.viewtoo.common.view.CommonSprite;
- import flash.events.Event;
- import fl.video.*;
- import flash.display.*;
- import flash.events.*;
- import flash.geom.*;
- /**
- * ...
- * @author Lancelot
- */
- public class VideoGridView extends Sprite {
- private var flvPlayer:FLVPlayback = null;
- private var len:Number = 3;
- private var _w:Number;
- private var _h:Number;
- //
- private var runObject:Array = [];
- public function VideoGridView() {
- super();
- }
- protected override function onAdded(evt:Event):void {
- super.onAdded(evt);
- flvPlayer = new FLVPlayback();
- flvPlayer.bufferTime = 3;
- flvPlayer.load("../mvGame/1.flv");
- flvPlayer.autoPlay = true;
- flvPlayer.addEventListener(MetadataEvent.METADATA_RECEIVED, onMetaData);
- }
- private function onMetaData(evt:MetadataEvent):void {
- flvPlayer.width = evt.info.width;
- flvPlayer.height = evt.info.height;
- _w = flvPlayer.width / len;
- _h = flvPlayer.height / len;
- flvPlayer.visible = false;
- addChild(flvPlayer);
- this.addEventListener(Event.ENTER_FRAME, onVideoEnterFrame);
- drawVideo();
- }
- // 开始照相
- private function onVideoEnterFrame(evt:Event):void {
- var l:Number = runObject.length;
- for (var i:Number = 0; i < l; i++) {
- var mybmp:BitmapData = runObject[i].mybmpdata;
- var matrix:Matrix = runObject[i].matrix;
- var rect:Rectangle = runObject[i].ract;
- // 绘制9个区域
- mybmp.draw(flvPlayer, matrix, null, null, rect);
- }
- }
- private function onImageMouseDownEvent(evt:MouseEvent):void {
- var maskView:Sprite = Sprite(evt.currentTarget);
- maskView.startDrag(false, null);
- maskView.addEventListener(MouseEvent.MOUSE_UP, onImageMouseUpEvent);
- }
- private function onImageMouseUpEvent(evt:MouseEvent):void {
- var maskView:Sprite = Sprite(evt.currentTarget);
- maskView.removeEventListener(MouseEvent.MOUSE_UP, onImageMouseUpEvent);
- maskView.stopDrag();
- }
- // 快照
- private function drawVideo():void {
- for (var x:Number = 0; x < len; x++) {
- for (var y:Number = 0; y < len; y++) {
- var obj:Object = new Object();
- var rect:Rectangle = new Rectangle(_w * x, _h * y, _w, _h);
- var matrix:Matrix = new Matrix(1, 0, 0, 1, -rect.x, -rect.y);
- // 避免误差
- rect.width += 1;
- var mybmp:BitmapData = new BitmapData(rect.width, rect.height);
- mybmp.draw(flvPlayer, matrix, null, null, rect);
- var sp:Sprite = new Sprite();
- sp.x = _w * x;
- sp.y = _h * y;
- sp.addEventListener(MouseEvent.MOUSE_DOWN, onImageMouseDownEvent);
- var bit:Bitmap = new Bitmap(mybmp);
- sp.addChild(bit);
- addChild(sp);
- runObject.push( { mybmpdata:mybmp, matrix:matrix, rect:rect } );
- }
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...