Outputing 300 DPI in Flex / Flash

This example uses the mx.graphics.ImageSnapshot class, which lets you take snapshot images of Flex user interface components. The underlying Flash Player API is flash.display.BitmapData.draw(). The maximum dimensions that BitmapData.draw() can capture is 2880×2880 pixels. By default, ImageSnapshot is also limited to this. ImageSnapshot has the following additional features:

•    Ability to specify an image format encoding (PNG is the default, JPG is the only other implementation.
•    For components that extend mx.core.UIComponent, calls UIComponent.prepareToPrint() and when finished calls UIComponent.finishPrint(). This lets you change the appearance of the component for capture; for example, remove selected item highlights.
•    Conversion of captured images to Base64-encoded Strings for text-based serialization purposes, such as embedding in XML)
•    Simple API to specify a desired resolution in dots per inch (DPI) that works out the underlying matrix required to scale the off-screen capture to a particular resolution.
•    Ability to controls whether the ImageSnapshot class tries to take multiple snapshots to support resolutions higher than 2880×2880 by stitching together several snapshots into one big ByteArray representing raw bitmap data before applying the encoding (for example, PNG). However, this is limited because a ByteArray can only hold 256 megabytes of data. Total composite image resolution is limited to about 8192×8192 . By default, the requested DPI is reduced until it fits inside 2880×2880 to avoid runtime errors.

The maximum DPI allowed when taking a snapshot depends on the dimensions of the component being captured and the on-screen resolution. The scale factor is the requested DPI divided by the on-screen resolution, which is then multiplied by the dimensions of the rectangular bounds of the user interface component being captured.
For example, suppose you have a component that is 400×300 pixels in area, has an on-screen resolution of 96 dpi, and a requested resolution is 300 dpi. The resulting scale factor is 300 / 96 = 3.125 times. Therefore, the captured image will be 1250 x 937.5 pixels.

Happy printing!

Share