原文地址:
如果你想保存从视频,图表或表格中获取的图片数据到本地,可以使用BitmapData类。
摘要:
使用BitmapData类来创建一个包含了从组件中获取的图片数据的对象,使用mx.graphics.codec包提供的方法编码为JPEG或PNG格式,然后使用AIR API提供的File和FileStream类保存到本地。
具体方法:
首先我们我们需要得到屏幕的截图,要做到这一点,我们要使用BitmapData类。比如我们想从一个命名为myChart的线状图表上获取截图:
import flash.display.BitmapData;
var bmpd:BitmapData = new BitmapData(myChart.width,myChart.height);
bmpd.draw(myChart);
然后我们需要把bitmapdata对象编译为ByteArray对象,这样我们就可以保存为文件了。这个ByteArray对象需要被格式化,我们可以使用mx.graphics.codec包中的JPEGEncoder和PNGEncoder类来实现它。
编码为JPEG格式:
import mx.graphics.codec.JPEGEncoder;
//create a new instance of the encoder, and set the jpeg compression level from 0 to 100
var jpgenc:JPEGEncoder = new JPEGEncoder(80);
//encode the bitmapdata object and keep the encoded ByteArray
var imgByteArray:ByteArray = jpgenc.encode(bmpd);
编码为PNG格式:
import mx.graphics.codec.JPEGEncoder;
//create a new instance of the encoder
var pngenc:PNGEncoder = new PNGEncoder();
//encode the bitmapdata object and keep the encoded ByteArray
var imgByteArray:ByteArray = pngenc.encode(bmpd);
现在我们已经准备好了ByteArray数据,我们只需要把它保存到本地就可以了。我们可以用File和File Stream类来实现。
建立一个JPEG文件参照:
//gets a reference to a new empty jpg image file in user desktop
var fl:File = File.desktopDirectory.resolvePath(”snapshot.jpg”);
AIR:如何保存图片到本地建立一个PNG文件参照:
//gets a reference to a new empty jpg image file in user desktop
var fl:File = File.desktopDirectory.resolvePath(”snapshot.png”);
现在我们可以把ByteArray用File Stream保存到文件中。
//Use a FileStream to save the bytearray as bytes to the new file
var fs:FileStream = new FileStream();
try{
//open file in write mode
fs.open(fl,FileMode.WRITE);
//write bytes from the byte array
fs.writeBytes(imgByteArray);
//close the file
fs.close();
} catch (e:Error){
trace(e.message);
}
分享到:
相关推荐
无线网络编码技术This paper proposes COPE, a new architecture for wireless mesh networks. In addition to forwarding packets, routers mix (i.e., code) packets from different sources to increase the in-...
flash air的一个小实例,选中一个文件,调用本地系统中默认文件关联程序打开。
AIR:基于QoS保障的空天信息网络路由算法,吕本伟,刘元安,由于空天信息网络应用环境及网络体系结构较为特殊,为了保证接入终端能够实现高速、可靠及大容量的数据收发,本文提出了一种基于
主要是关于AIR操作本地文件夹的例子。 功能: 通过选择的图片生成一个新的swf图片浏览器 并且有本地打开和本地保存功能 ...然后点保存 可以把生成的swf保存到指定路径 然后关闭窗口 你可以查看新的swf
使用air读取本地文件并插入到sqlite数据库
AIR 的本地数据库访问。本文档主要描述AIR的本地数据库访问。
//AS3将文本文件保存到本地 仅5行代码 多么简单 import flash.net.FileReference; var fileRef:FileReference = new FileReference();
NULL 博文链接:https://lxs647.iteye.com/blog/1179043
本AS3类用于AIR的本地程序开发,利用FILE类进行整理,可以支持将本地位置的文件夹进行遍历,并生成XML格式文件。
将 AIR 文件下载到用户的计算机 检查应用程序是否为首次运行 使用更新框架 第 17 章: 查看源代码 加载、配置和打开 Source Viewer Source Viewer 用户界面 第 18 章: 使用 AIR HTML 内部检查器进行调试 关于 ...
iPad Air 2 ad: change
将custom_components / blueair复制到HomeAssistant基本配置目录(configuration.yaml所在的目录) 使用您的凭证配置blueair传感器 sensor : - platform : blueair user : " <you>@gmail.com " password : " ...
FlashAirFileManager 英文/FlashAirFileManager是允许您通过网络在FlashAir:trade_mark:上浏览和下载文件的应用程序。 是东芝存储器出售的具有无线LAN功能的SD卡。 是一项Web服务,支持使用FlashAir进行原始系统开发...
flashair-lua-dev:东芝:registered:FlashAir:registered:Wi-Fi SD卡存根
adobe AIR的本地框架FluorineFx Aperture 通过它AIR应用程序能够直接调用使用C,C++,C#等编写的类库。
air 模拟普通网页的multipart/form-data提交方式,实现本地文件上传到远程服务器。本例没有服务端获取的解析代码,需要下载的朋友自己简单实现。
AIR android本地扩展
AirPrint无线打印技术当前仅面向Mac开放,并且只能在几款惠普打印机上实现。没有这些AirPrint兼容打印机的可以借助一款名为Printopia的Mac程序激活AirPrint功能,那么Windows用户呢?想在PC上启用AirPrint的Windows...
Airplay3 最小巧华丽在线和本地音乐播放器 2011年7月31号开发的一个内部开发版, 更新内容: 升级播放引擎,降低CPU消耗并改善切换歌曲时的平滑衔接 + 音乐窗口显示菜单增加【自动隐藏分类】功能 + 优化几处操作体验...