何涛

最近更新

Flex专栏‎ > ‎

Flex3截屏最简单的方法

发布者:何涛,发布时间:2009-5-14 下午8:02   [ 更新时间:2009-5-14 下午8:10 ]
用ImageSnapshot里的静态方法可以轻松的取到,下面是例子,这个例子我把它编成了base64 的代码,在flash端得到这个代码后可以轻松的通过各种方法发给php等服务端来保存成自己的图片。

as源码

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:Script>
        <![CDATA[
       
       
        import mx.graphics.ImageSnapshot;
        import mx.core.UIComponent;
        import mx.controls.Alert;
       
        public function takeSnapshot(target:UIComponent) :void
        {
            var shot:ImageSnapshot = ImageSnapshot.captureImage(target);
            Alert.show(ImageSnapshot.encodeImageAsBase64(shot));
        }
       
       
        ]]>
       
    </mx:Script>

    <mx:Button click="takeSnapshot(targetPanel)" label="Save Image" x="10" y="100"/>
   
    <mx:Panel id="targetPanel" layout="vertical">
    <mx:Label text="Hello World"  y="9"/>
    <mx:Image  source="http://www.google.cn/images/nav_logo4.png"/>
    </mx:Panel>

</mx:Application>


这是php例子,代码更简单。

PHP代码

<?php
$base64_string = "";
file_put_contents("test_1.png",base64_decode($base64_string));
?>