/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<mx:HTTPService id="screencap" url="http://demo.ribbit.mobi/heartbeat/storeImage.php" method="POST" resultFormat="e4x" result="screencapSuccess(event);" fault="screencapError(event);"> <mx:request> <screencapImg>{encodedData}</screencapImg> </mx:request> </mx:HTTPService> public function takeSnapshot(target:UIComponent) :void { var bd:BitmapData = new BitmapData(target.width,target.height); bd.draw(target); //var ba:ByteArray = PNGenc.encode(bd); var jpgEncoder:JPGEncoder = new JPGEncoder(100); var ba:ByteArray = jpgEncoder.encode(bd); var be:Base64Encoder = new Base64Encoder(); be.encodeBytes(ba); encodedData = be.flush(); //ro.saveImage(encodedData); screencap.send(); } <?php $encodedPNGData = $_POST['screencapImg']; $binaryData = base64_decode($encodedPNGData); $file = "/tmp/heartbeat_current.jpg"; file_put_contents($file, $binaryData); ?>