Flex中如何利用ImageSnapshot类的defaultEncoder属性给截图设置一个默认译码器的例子
By Minidxer | December 31, 2008
和前面Flex中如何利用encodeImageAsBase64()事件将一个ImageSnapshot对象转化为Base-64编码字符串的例子类似的,接下来的例子演示了Flex中如何利用ImageSnapshot类的defaultEncoder属性,给截图设置一个默认译码器。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- creationComplete="init();">
- <mx:Script>
- <![CDATA[
- import mx.graphics.ImageSnapshot;
- import mx.graphics.codec.*;
- private function init():void {
- ImageSnapshot.defaultEncoder = PNGEncoder;
- }
- private function captureImg():void {
- var ohSnap:ImageSnapshot = ImageSnapshot.captureImage(img);
- textArea.text = ImageSnapshot.encodeImageAsBase64(ohSnap);
- lbl.text = ohSnap.contentType;
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar dock="true">
- <mx:Button id="button"
- label="Capture Image"
- click="captureImg();" />
- </mx:ApplicationControlBar>
- <mx:Form>
- <mx:FormItem label="source:">
- <mx:Image id="img"
- source="@Embed('images/flex_logo.jpg')" />
- </mx:FormItem>
- <mx:FormItem label="Base64:">
- <mx:TextArea id="textArea"
- editable="false"
- width="320"
- height="160" />
- </mx:FormItem>
- <mx:FormItem label="contentType:">
- <mx:Label id="lbl" />
- </mx:FormItem>
- </mx:Form>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Other |
No Comments » |
316 views
Tags: captureImage(), defaultEncoder, encodeImageAsBase64(), ImageSnapshot, PNGEncoder.