flex4 操作word文档

来源:互联网 发布:学会了单片机再学plc 编辑:程序博客网 时间:2024/04/29 19:53
对于word,可将word文档模板文件存成xml格式,而此xml文档中的图片是以“base-64 encoded”,而flex4可以将生成的图片快照下来再转换成此格式,flex能够操作xml文件,从而可以修改word xml模板文件中的内容,从而与word协作。
将ImageSnapshot对象利用flex4的encodeImageAsBase64()方法转换为base-64 encoded格式的例子:
<?xml version="1.0" encoding="utf-8"?><!-- http://blog.flexexamples.com/2007/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/ --><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"layout="vertical"verticalAlign="middle"backgroundColor="white"><mx:Script><![CDATA[import flash.events.FocusEvent;import flash.system.System;import mx.graphics.ImageSnapshot;private function button_click(evt:MouseEvent):void {var ohSnap:ImageSnapshot = ImageSnapshot.captureImage(img);textArea.text = ImageSnapshot.encodeImageAsBase64(ohSnap);}private function textArea_focusIn(evt:FocusEvent):void {textArea.setSelection(0, textArea.text.length);}]]></mx:Script><mx:ApplicationControlBar dock="true"><mx:Button label="Capture and encode"click="button_click(event);" /></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"showScrollTips="true"width="320"height="160"focusIn="textArea_focusIn(event);" /></mx:FormItem><mx:FormItem><mx:Button label="Copy to clipboard"enabled="{textArea.text.length > 0}"click="System.setClipboard(textArea.text);" /></mx:FormItem></mx:Form></mx:Application>
mx.graphics.ImageSnapshot 是一种帮助器类,用于捕获实现了 flash.display.IBitmapDrawable 的任何 Flash 组件(包括 Flex UIComponent)的快照。

将base-64 encoded文本转换为图片可以使用开源的flexlib.controls.Base64Image类实现。这里是示例。
0 0
原创粉丝点击