加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex 3中利用ImageSnapshot类捕获JPEG或PNG形式图片的例子

发布时间:2020-12-15 04:25:22 所属栏目:百科 来源:网络整理
导读:下面的例子展示了如何在Flex 3中,通过设置ImageSnapshot类中的 encoder 参数和调用静态 captureImage()事件,捕获JPEG或PNG形式图片。 下面是具体的源代码: Download:? main.mxml ? xml ? version = " 1.0 " ? encoding = " utf-8 " ? mx : Application ?

下面的例子展示了如何在Flex 3中,通过设置ImageSnapshot类中的 encoder参数和调用静态 captureImage()事件,捕获JPEG或PNG形式图片。
下面是具体的源代码:
Download:? main.mxml
  1. <?xml?version="1.0"?encoding="utf-8"?>
  2. <mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"
  3. ? ? ? ??layout="vertical"
  4. ? ? ? ??verticalAlign="middle"
  5. ? ? ? ??backgroundColor="white">
  6. ? ? <mx:Script>
  7. ? ? ? ? <![CDATA[
  8. ? ? ? ? ? ??import?mx.graphics.ImageSnapshot;
  9. ? ? ? ? ? ??import?mx.graphics.codec.*;
  10. ? ? ? ? ? ??private?const?jpgEnc:JPEGEncoder?=?new?JPEGEncoder();
  11. ? ? ? ? ? ??private?const?pngEnc:PNGEncoder?=?new?PNGEncoder();
  12. ? ? ? ? ? ??private?function?captureImg(imgEnc:IImageEncoder):void?{
  13. ? ? ? ? ? ? ? ??var?ohSnap:ImageSnapshot;
  14. ? ? ? ? ? ? ? ??ohSnap?=?ImageSnapshot.captureImage(img,?0,?imgEnc);
  15. ? ? ? ? ? ? ? ??textArea.text?=?ImageSnapshot.encodeImageAsBase64(ohSnap);
  16. ? ? ? ? ? ??}
  17. ? ? ? ??]]>
  18. ? ? </mx:Script>
  19. ? ? <mx:ApplicationControlBar dock="true">
  20. ? ? ? ? <mx:ToggleButtonBar id="toggleButtonBar"
  21. ? ? ? ? ? ? ? ? itemClick="captureImg(event.item.data);">
  22. ? ? ? ? ? ? <mx:dataProvider>
  23. ? ? ? ? ? ? ? ? <mx:Array>
  24. ? ? ? ? ? ? ? ? ? ? <mx:Object label="Capture as JPEG" data="{jpgEnc}"?/>
  25. ? ? ? ? ? ? ? ? ? ? <mx:Object?label="Capture as PNG"?data="{pngEnc}"?/>
  26. ? ? ? ? ? ? ? ? </mx:Array>
  27. ? ? ? ? ? ? </mx:dataProvider>
  28. ? ? ? ? </mx:ToggleButtonBar>
  29. ? ? </mx:ApplicationControlBar>
  30. ? ? <mx:Image id="img"
  31. ? ? ? ? ? ? source="@Embed('images/flex_logo.jpg')" />
  32. ? ? <mx:TextArea id="textArea"
  33. ? ? ? ? ? ? editable="false"
  34. ? ? ? ? ? ? width="320"
  35. ? ? ? ? ? ? height="160" />
  36. </mx:Application>

转载:http://www.voidcn.com/article/p-vmdhnzyh-od.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读