下面的例子展示了如何在Flex 3中,通过设置ImageSnapshot类中的
encoder
参数和调用静态
captureImage()事件,捕获JPEG或PNG形式图片。
下面是具体的源代码:
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">
-
? ? <mx:Script>
-
? ? ? ? <![CDATA[
-
? ? ? ? ? ??import?mx.graphics.ImageSnapshot;
-
? ? ? ? ? ??import?mx.graphics.codec.*;
-
? ? ? ? ? ??private?const?jpgEnc:JPEGEncoder?=?new?JPEGEncoder();
-
? ? ? ? ? ??private?const?pngEnc:PNGEncoder?=?new?PNGEncoder();
-
? ? ? ? ? ??private?function?captureImg(imgEnc:IImageEncoder):void?{
-
? ? ? ? ? ? ? ??var?ohSnap:ImageSnapshot;
-
? ? ? ? ? ? ? ??ohSnap?=?ImageSnapshot.captureImage(img,?0,?imgEnc);
-
? ? ? ? ? ? ? ??textArea.text?=?ImageSnapshot.encodeImageAsBase64(ohSnap);
-
? ? ? ? ? ??}
-
? ? ? ??]]>
-
? ? </mx:Script>
- ? ? <mx:ApplicationControlBar dock="true">
- ? ? ? ? <mx:ToggleButtonBar id="toggleButtonBar"
- ? ? ? ? ? ? ? ? itemClick="captureImg(event.item.data);">
- ? ? ? ? ? ? <mx:dataProvider>
- ? ? ? ? ? ? ? ? <mx:Array>
-
? ? ? ? ? ? ? ? ? ? <mx:Object label="Capture as JPEG" data="{jpgEnc}"?/>
-
? ? ? ? ? ? ? ? ? ? <mx:Object?label="Capture as PNG"?data="{pngEnc}"?/>
-
? ? ? ? ? ? ? ? </mx:Array>
-
? ? ? ? ? ? </mx:dataProvider>
-
? ? ? ? </mx:ToggleButtonBar>
-
? ? </mx:ApplicationControlBar>
- ? ? <mx:Image id="img"
-
? ? ? ? ? ? source="@Embed('images/flex_logo.jpg')" />
- ? ? <mx:TextArea id="textArea"
- ? ? ? ? ? ? editable="false"
- ? ? ? ? ? ? width="320"
- ? ? ? ? ? ? height="160" />
- </mx:Application>
转载:http://www.voidcn.com/article/p-vmdhnzyh-od.html