Actionscript 3.0让我们在iDevice上截取屏幕截图

时间:2012-03-29 01:25:56

标签: actionscript-3 air

我想知道如何使用Actionscript 3拍摄屏幕并保存到iPad,我的代码适用于adobe flash player和Android平板电脑。但它不适用于iPad。有什么建议吗?

/**
* ScreenCapture
* 
* This function take the abliity to print screen the stage and ready to output to the user to view
*
*/      
package actions{
    import flash.errors.IllegalOperationError;
    import flash.errors.MemoryError;
    import flash.net.FileReference;
    import flash.display.MovieClip;
    import flash.events.IOErrorEvent;
    import flash.display.BitmapData;
    import flash.utils.ByteArray;
    import flash.display.Sprite;

    import com.adobe.images.JPGEncoder;
    import utility.Base64;

    public class ScreenCapture extends Sprite{

        public function ScreenCapture() {
        }

        /**
        * saveImage
        * 
        * Seek into the container and find how many child is in the container
        *
        * @param    image   the movieclip about to be print screened
        * @param    imageName   the number of the image file
        */  
        public function saveImage(type:String, image:MovieClip, imageName:String) {
            //try {
                var jpgSource:BitmapData = new BitmapData( image.width, image.height );
                jpgSource.draw(image);
                var jpgEncoder:JPGEncoder = new JPGEncoder(85);
                var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
                if(type == 'fileSave'){
                    var file:FileReference = new FileReference();
                    //file.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
                    file.save( jpgStream, imageName );
                }else if(type == 'fetchImg'){
                    return jpgStream;
                }
            //}
            /**catch( ioe:IllegalOperationError ) {
                trace("Illegal operation.");
            }
            catch( ae:ArgumentError ) {
                trace("Invalid argument.");
            }
            catch( me:MemoryError ) {
                trace("Insufficient memory.");
            }
            catch( error:Error ) {
                trace("Error trying to save image : " + imageName 
                      + " . Error : " + error);
            }*/
        }

        /**
        * Handles IOErrors.
        */
        /**private function ioErrorHandler( event:IOErrorEvent ) : void {
            trace("ioErrorHandler: " + event);
        }*/

    }

}

任何帮助或建议表示赞赏。感谢

1 个答案:

答案 0 :(得分:0)

发现解决方案CameraRoll是我需要的Class!