Package | com.yworks.remote |
Class | public class AbstractImageExportHandler |
Inheritance | AbstractImageExportHandler flash.events.EventDispatcher |
Subclasses | ImageExportHandler, ImageSaveHandler |
Implentations are ImageExportHandler
and FileImageExportHandler
.
See also
Property | Defined By | ||
---|---|---|---|
maxImageSize : ISize
Get or set the maximum allowed image size. | AbstractImageExportHandler |
Property | Defined By | ||
---|---|---|---|
fileReference : FileReference
The FileReference which handles the file operations. | AbstractImageExportHandler |
Method | Defined By | ||
---|---|---|---|
export(canvas:CanvasComponent, defaultFileName:String, exportOptions:ExportOptions = null, canvasSprite:Sprite = null):void
Exports the image using the provided export options. | AbstractImageExportHandler |
Method | Defined By | ||
---|---|---|---|
createFileReference():FileReference
Creates a new FileReference and sets the fileReference
property. | AbstractImageExportHandler | ||
createImageAsByteArray(canvas:CanvasComponent, exportOptions:ExportOptions, canvasSprite:Sprite = null):ByteArray
Create a ByteArray which contains an encoded image of the canvas. | AbstractImageExportHandler | ||
decorateExportSprite(sprite:Sprite, m:Matrix, exportOptions:ExportOptions, canvas:CanvasComponent):void
Callback that allows additional painting on the sprite that will be exported as a bitmap. | AbstractImageExportHandler | ||
encodeBitmap(bitmap:BitmapData):ByteArray
Encodes the given bitmap data to a byte array. | AbstractImageExportHandler | ||
exportCore(canvas:CanvasComponent, defaultFileName:String, exportOptions:ExportOptions = null, canvasSprite:Sprite = null):void
This method is called by the export method and is expected to create the image file
and save or download it using a FileReference created by createFileReference(). | AbstractImageExportHandler | ||
getImageData(canvas:CanvasComponent, exportOptions:ExportOptions, canvasSprite:Sprite = null):BitmapData
Draws the canvas contents to a BitmapData instance. | AbstractImageExportHandler | ||
onCancel(event:Event):void
Called when the user chose the cancel button of the download dialog. | AbstractImageExportHandler | ||
onComplete(evt:Event):void
Called when the export operation has finished succesfully. | AbstractImageExportHandler | ||
onHTTPStatus(evt:HTTPStatusEvent):void
Called when the server sends a HTTP status. | AbstractImageExportHandler | ||
onIOError(evt:IOErrorEvent):void
Called when an IO error occurs while executing the image file download. | AbstractImageExportHandler | ||
onProgress(evt:ProgressEvent):void
Dispatched periodically during the file upload or download operation. | AbstractImageExportHandler | ||
onSecurityError(evt:SecurityErrorEvent):void
Called when a security error occurs while executing the image file download. | AbstractImageExportHandler | ||
onSelect(evt:Event):void
Called when the user has selected a location for the image file download. | AbstractImageExportHandler |
fileReference | property |
fileReference:FileReference
The FileReference which handles the file operations.
protected function get fileReference():FileReference
protected function set fileReference(value:FileReference):void
maxImageSize | property |
maxImageSize:ISize
Get or set the maximum allowed image size.
The size of the exported image will not exceed the size defined by this property.
Note that earlier Flash Player versions have limited bitmap sizes. For Flash Player 9 and earlier the maximum size
should not be larger than 2880x2880
.
Flash Player 10 allows a maximum width or height of 8191
pixels and a total number of 16,777,215
pixels. Since Flash Player 11 there is no size limit.
public function get maxImageSize():ISize
public function set maxImageSize(value:ISize):void
See also
createFileReference | () | method |
protected function createFileReference():FileReference
Creates a new FileReference
and sets the fileReference
property.
This method registers all event listeners to the appropriate callbacks and
thus should be used to create the file reference in the exportCore
method.
FileReference — A file reference instance.
|
createImageAsByteArray | () | method |
protected function createImageAsByteArray(canvas:CanvasComponent, exportOptions:ExportOptions, canvasSprite:Sprite = null):ByteArray
Create a ByteArray
which contains an encoded image of the canvas.
A pre-calculated Sprite
containing a copy of the canvas object tree can be passed to support
the export of lazy-loading image data.
Parameters
canvas:CanvasComponent — The canvas that should be exported to a bitmap.
| |
exportOptions:ExportOptions — The export options for this export.
| |
canvasSprite:Sprite (default = null ) — A pre-calculated canvas Sprite .
|
ByteArray — A byte array which contains an encoded image of the canvas.
|
See also
decorateExportSprite | () | method |
protected function decorateExportSprite(sprite:Sprite, m:Matrix, exportOptions:ExportOptions, canvas:CanvasComponent):void
Callback that allows additional painting on the sprite that will be exported as a bitmap.
Parameters
sprite:Sprite — The sprite that will be exported as a bitmap.
The canvas has already been painted on a child display object of the passed Sprite.
| |
m:Matrix — The matrix that is used to scale, rotate, or translate the coordinates of the bitmap. The matrix is already
configured according to the scaleMode set on the exportOptions parameter.
| |
exportOptions:ExportOptions — The export options.
| |
canvas:CanvasComponent — The canvas that should be exported to a bitmap.
|
encodeBitmap | () | method |
protected function encodeBitmap(bitmap:BitmapData):ByteArray
Encodes the given bitmap data to a byte array.
The default implementation uses PNG encoding.
Parameters
bitmap:BitmapData — The bitmap data to be encoded
|
ByteArray — A byte array containing the encoded bitmap data.
|
export | () | method |
public function export(canvas:CanvasComponent, defaultFileName:String, exportOptions:ExportOptions = null, canvasSprite:Sprite = null):void
Exports the image using the provided export options.
In general, to make sure that asynchronous content is exported correctly, a sprite containing
the canvas content should be passed using the canvasSprite
parameter. For example,
if the ImageNodeStyle
is used with a remote SWF, the SWF will not be visible in the
exported bitmap if this method is called directly without passing a pre-rendered sprite.
Also, as this method will use a Flex FileReference
instance to open a save dialog, this method
should only be called in direct response to a user event (e.g. a mouse click or keypress handler).
Otherwise, a security error will be thrown. The below example shows how the export function can be called
with a pre-rendered sprite.
Parameters
canvas:CanvasComponent — The graph canvas component containing the graph that is serialized.
| |
defaultFileName:String — The default file name to be shown in the browser's download dialog.
| |
exportOptions:ExportOptions (default = null ) — The export options for this export.
| |
canvasSprite:Sprite (default = null ) — A Sprite containing the canvas content. If no sprite is passed,
CanvasComponent#createSprite() is used to create the sprite that will be exported.
This may cause asynchronous content to be left out from the exported bitmap data. Please see the above
example for details.
|
See also
// create a sprite containing the canvas content var printSprite:PrintSprite = canvasComponent.createSprite(); // create a dialog that will not be shown until the sprite has finished rendering // any asynchronous content. As an alternative, we could also show the dialog immediately, // but enable the dialogs' submit button only when the canvas has finished rendering. var dialog:MyDialog = new MyExportDialog(); dialog.addEventListener(MyDialogEvent.OK,function(evt:MyDialogEvent):void { // When a submit button is pressed in the custom dialog, this event is dispatched. // We can now call the export function in direct response to the user event // (mouse click on the ok button). new ImageSaveHandler().export(canvasComponent, "export.png", myExportOptions, printSprite); }); if(!printSprite.paintComplete) { var onPaintComplete:Function = function(evt:Event):void { printSprite.removeEventListener(Event.COMPLETE,onPaintComplete); showDialog(dialog); }; printSprite.addEventListener(Event.COMPLETE,onPaintComplete); } else { showDialog(dialog); }
Event handling can be customized by overriding the various protected event handler functions.
exportCore | () | method |
protected function exportCore(canvas:CanvasComponent, defaultFileName:String, exportOptions:ExportOptions = null, canvasSprite:Sprite = null):void
This method is called by the export
method and is expected to create the image file
and save or download it using a FileReference
created by createFileReference()
.
Subclasses have to override this method.
Parameters
canvas:CanvasComponent — The canvas to create the image from.
| |
defaultFileName:String — A default file name.
| |
exportOptions:ExportOptions (default = null ) — The export options.
| |
canvasSprite:Sprite (default = null ) — An optional pre-calculated sprite to create the image file from.
|
getImageData | () | method |
protected function getImageData(canvas:CanvasComponent, exportOptions:ExportOptions, canvasSprite:Sprite = null):BitmapData
Draws the canvas contents to a BitmapData
instance.
A pre-calculated Sprite
containing a copy of the canvas object tree can be passed to support
the export of lazy-loading image data.
Parameters
canvas:CanvasComponent — The canvas that is to be exported to a bitmap.
| |
exportOptions:ExportOptions — The export options.
| |
canvasSprite:Sprite (default = null ) — A pre-calculated canvas Sprite .
|
BitmapData — A bitmap representation of the current canvas contents.
|
See also
onCancel | () | method |
protected function onCancel(event:Event):void
Called when the user chose the cancel button of the download dialog.
Parameters
event:Event |
onComplete | () | method |
protected function onComplete(evt:Event):void
Called when the export operation has finished succesfully.
This implementation removes the busy cursor.
Parameters
evt:Event |
onHTTPStatus | () | method |
protected function onHTTPStatus(evt:HTTPStatusEvent):void
Called when the server sends a HTTP status.
This implementation is empty.
Parameters
evt:HTTPStatusEvent |
onIOError | () | method |
protected function onIOError(evt:IOErrorEvent):void
Called when an IO error occurs while executing the image file download.
This implementation shows an alert message, traces the event and removes the busy cursor.
Parameters
evt:IOErrorEvent |
onProgress | () | method |
protected function onProgress(evt:ProgressEvent):void
Dispatched periodically during the file upload or download operation.
The progress event is dispatched while Flash Player transmits bytes to a server, and it is periodically dispatched during the transmission, even if the transmission is ultimately not successful. To determine if and when the file transmission is actually successful and complete, listen for the complete event.
In some cases, progress events are not received. For example, when the file being transmitted is very small or the upload or download happens very quickly a progress event might not be dispatched.
This implementation does nothing.
Parameters
evt:ProgressEvent |
onSecurityError | () | method |
protected function onSecurityError(evt:SecurityErrorEvent):void
Called when a security error occurs while executing the image file download.
This implementation shows an alert message, traces the event and removes the busy cursor.
Parameters
evt:SecurityErrorEvent |
onSelect | () | method |
protected function onSelect(evt:Event):void
Called when the user has selected a location for the image file download.
This implementation sets the busy cursor.
Parameters
evt:Event |