[AS3]as3.0利用JPGEncoder或PNGEncoder将图片序列化
[AS3]as3.0利用JPGEncoder或PNGEncoder将图片序列化,图片序列化,JPGEncoder,PNGEncoder
[AS3]as3.0利用JPGEncoder或PNGEncoder将图片序列化
- import flash.events.MouseEvent;
- import flash.utils.ByteArray;
- import com.adobe.images.JPGEncoder;
- import flash.display.Bitmap;
- var bytes:ByteArray;
- var bit:SampleImage;//cuplayer.com提示SampleImage是库中的图片链接"类名"
- //将图片序列化为ByteArray
- function btnEncodeClick(e:MouseEvent):void {
- var jpg:JPGEncoder = new JPGEncoder();
- bytes = jpg.encode(bit);
- txtArray.text = "";
- for (var i:uint=0,j=bytes.length; i<j; i++) {
- txtArray.appendText(bytes[i].toString() + ",");
- }
- if (txtArray.text.length > 0) {
- txtArraytxtArray.text = txtArray.text.substring(0,txtArray.text.length - 1);
- }
- btnEncode.enabled = false;
- btnEncode.removeEventListener(MouseEvent.CLICK,btnEncodeClick);
- btnDecode.addEventListener(MouseEvent.CLICK,btnDecodeClick);
- }
- //将ByteArray反序列化为图象
- function btnDecodeClick(e:MouseEvent):void {
- if (bytes==null){return;}
- var _ld:Loader = new Loader();
- _ld.loadBytes(bytes);
- _ld.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
- btnDecode.enabled = false;
- btnDecode.removeEventListener(MouseEvent.CLICK,btnDecodeClick);
- }
- //加载完成的回调函数
- function onComplete(e:Event):void {
- var bitMap:Bitmap = e.target.content as Bitmap;//读取Bitmap
- addChild(bitMap);
- bitMap.y = 7;
- bitMap.x = 330;
- }
- function init():void{
- bit = new SampleImage();
- var bitMap:Bitmap = new Bitmap(bit);
- bitMap.x = 100;
- bitMap.y = 7;
- addChild(bitMap);
- btnEncode.addEventListener(MouseEvent.CLICK,btnEncodeClick);
- }
- init();
热门文章推荐
- [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示例
请稍候...