3、 Flex中Image控件相关之Image Base64 Encode and Decode (Flex 图像进行Base64加密与解密)(Flex文件上传

Flex中Image控件相关之Image Base64 Encode and Decode (Flex 图像进行Base64加密与解密)(Flex文件上传)

上代码<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	
	<fx:Script>
		<![CDATA[
			import comp.util.ImageProcessUtil;
			
			import mx.utils.Base64Decoder;
			import mx.utils.Base64Encoder;
			protected function button1_clickHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				var byteArray:ByteArray = ImageProcessUtil.BitmapDataToByteArray(source);
				
				var base64Encoding:Base64Encoder = new Base64Encoder();
				
				base64Encoding.encodeBytes(byteArray,0,byteArray.length);
				
				txt_area.text = base64Encoding.toString();
				//和java交互,保存base64Encoding.toString()到数据库
			}
			
			protected function button2_clickHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				//和java交互读取数据库,转变成图像
				var base64Decoding:Base64Decoder  = new Base64Decoder();
				base64Decoding.decode(txt_area.text);
				resultImage.source = ImageProcessUtil.ByteArrayToBitmap(base64Decoding.toByteArray());
				
			}
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	
	
	<mx:Image id="source" x="94" y="58" width="83" height="80" autoLoad="true" scaleContent="true"
			  source="assets/images/map.jpg" maintainAspectRatio="true"/>
	<s:Button x="118" y="146" width="30" height="60" label="||" click="button1_clickHandler(event)"/>
	<s:TextArea id="txt_area" x="28" y="225" width="363"/>
	<s:Button x="399" y="283" width="63" height="35" label="==》" click="button2_clickHandler(event)"/>
	<s:Image id="resultImage" x="489" y="259" width="199" height="80"/>
</s:Application>
 

你可能感兴趣的:(Flex文件上传,Flex中Image控件)