Save a bitmap to anything in AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <mx:HTTPService id="screencap" url="http://demo.ribbit.mobi/heartbeat/storeImage.php" method="POST" resultFormat="e4x" result="screencapSuccess(event);" fault="screencapError(event);">
  2. <mx:request>
  3. <screencapImg>{encodedData}</screencapImg>
  4. </mx:request>
  5. </mx:HTTPService>
  6.  
  7.  
  8. public function takeSnapshot(target:UIComponent) :void
  9. {
  10. var bd:BitmapData = new BitmapData(target.width,target.height);
  11. bd.draw(target);
  12. //var ba:ByteArray = PNGenc.encode(bd);
  13. var jpgEncoder:JPGEncoder = new JPGEncoder(100);
  14. var ba:ByteArray = jpgEncoder.encode(bd);
  15. var be:Base64Encoder = new Base64Encoder();
  16. be.encodeBytes(ba);
  17. encodedData = be.flush();
  18. //ro.saveImage(encodedData);
  19. screencap.send();
  20. }
  21.  
  22. <?php
  23. $encodedPNGData = $_POST['screencapImg'];
  24. $binaryData = base64_decode($encodedPNGData);
  25. $file = "/tmp/heartbeat_current.jpg";
  26. file_put_contents($file, $binaryData);
  27. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.