views:

457

answers:

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.

A: 

Take a look at the answer to this: Thumbnails of components

I've used a very similar function and it was pretty fast, so hopefully you'll have no problem doing it that way.

CookieOfFortune
+2  A: 

Check out the fllowing URL, it is an open source JPEG encoder which is over 4 times faster than the one in corelibs.

http://www.bytearray.org/?p=775

Simon
A: 

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).

Daniel