Search code examples
actionscript-3flex3screenshot

Fastest way to take a Screenshot in Flex 3?


What's the fastest way to get a screen capture in flex? I am currently using: (I currently encode it to Base64 for upload to a webserver, but this is not necessarily required. All I want is an image file to appear on the server).

  ImageSnapshot.defaultEncoder = JPEGEncoder;
  var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(<< flex component >>);
  var screenshotData:String = ImageSnapshot.encodeImageAsBase64(imageSnap);

It currently holds up the entire application for almost a second as it actually captures the image. The Base64 encoding happens essentially instantaneously.


Solution

  • The open-source JPEG encoder is not any faster than the mx.codecs one, unfortunately. However, the build in PNG encoder is about 6x as fast as the JPEG encoder. This solves the problem that I was currently having, i.e. too slow compression.

    The "thumbnails of components" answer from CookieOfFortune solves another problem, that of taking the snapshot separately from compression, (snapshotting takes ~5ms for me, compression, now, <500ms).