| Package | com.flexblocks.imagecropper |
| Class | public class ImageCropper |
| Inheritance | ImageCropper mx.core.UIComponent |
String (URL) pointing to an image file, or a BitmapData object that contains an image, and displays the image within the
component. If the size of the image exceeds the component's dimensions then the image is scaled so that it will entirely fit within the component.
The image may be visually cropped by adjusting the boundries of a cropping rectangle using any of the four handles on the corners
of the rectangle. At any time a BitmapData object containing the cropped portion of the image may be retrieved, or
a Rectangle may be retrieved that defines the cropped portion of the image.
The cropping rectangle may be initialized using coordinates and dimensions relative to the component's display or relative to the source image.
| Property | Defined by | ||
|---|---|---|---|
| backgroundAlpha : Number
The level of transparency (0 to 1) for the component's background.
| ImageCropper | ||
| backgroundColor : uint
The background color for the component.
| ImageCropper | ||
| constrainToAspectRatio : Boolean
If set to
true then the cropping rectangle will always maintain the aspect ratio that was active when the constrainToAspectRatio property was set. | ImageCropper | ||
| croppedBitmapData : BitmapData [read-only]
The cropped source image as a
BitmapData object. | ImageCropper | ||
| enabled : Boolean
Whether the component can accept user interaction or changes to properties.
| ImageCropper | ||
| handleAlpha : Number
The level of transparency (0 to 1) for the four corner handles of the cropping rectangle.
| ImageCropper | ||
| handleColor : uint
The color used for the four corner handles of the cropping rectangle.
| ImageCropper | ||
| handleSize : Number
The size of each of the four corner handles of the cropping rectangle.
| ImageCropper | ||
| maskAlpha : Number
The level of transparency (0 to 1) for the mask that is used to indicate the non-selected portion of the cropped image.
| ImageCropper | ||
| maskColor : uint
The color of the mask used to indicate the non-selected portion of the cropped image.
| ImageCropper | ||
| outlineAlpha : Number
The level of transparency (0 to 1) used for the single pixel outline drawn around the cropping rectangle and around the four corner handles of the cropping rectangle.
| ImageCropper | ||
| outlineColor : uint
The color used for single pixel outline drawn around the cropping rectangle and around the four corner handles of the cropping rectangle.
| ImageCropper | ||
| sourceImage : Object
Either a
String that contains a URL pointing to an image or a BitmapData object that contains an image. | ImageCropper | ||
| Method | Defined by | ||
|---|---|---|---|
|
Class constructor.
| ImageCropper | ||
|
destroy():void
Call this method to dereference resources when the
ImageCropper component is no longer needed. | ImageCropper | ||
|
getCropRect(componentRelative:Boolean = false, roundValues:Boolean = false):Rectangle
Returns the position and the dimensions of the cropped portion of the image as a
Rectangle. | ImageCropper | ||
|
setCropRect(width:Number = 0, height:Number = 0, x:Number = -1, y:Number = -1, componentRelative:Boolean = false):void
This method defines the position and the dimensions of the cropping rectangle within the component.
| ImageCropper | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
This event is dispatched whenever constrainToAspectRatio is set to true and the component alters the aspect ratio of the cropping rectangle. | ImageCropper | |||
If constrainToAspectRatio is set to true and a call to setCropRect is executed with a width or height value less than or equal to zero,
then constrainToAspectRatio will be disabled and this event will be dispatched. | ImageCropper | |||
| This event is dispatched whenever the component alters the dimensions of the cropping rectangle. | ImageCropper | |||
| This event is dispatched whenever the component alters the position of the cropping rectangle. | ImageCropper | |||
| This event is dispatched whenever the cropping rectangle is resized or repositioned using the mouse. | ImageCropper | |||
| This event is dispatched if an I/O error occurs while loading an image from a URL. | ImageCropper | |||
| This event is dispatched when the component begins loading an image from a URL. | ImageCropper | |||
This event is dispatched when the component has completed loading an image from a URL or when a BitmapData object is specified for the sourceImage parameter. | ImageCropper | |||
| Constant | Defined by | ||
|---|---|---|---|
| CROP_CONSTRAINT_CHANGED : String = "cropConstraintChanged"
Constant value for the
cropConstraintChanged event. | ImageCropper | ||
| CROP_CONSTRAINT_DISABLED : String = "cropConstraintDisabled"
Constant value for the
cropConstraintDisabled event. | ImageCropper | ||
| CROP_DIMENSIONS_CHANGED : String = "cropDimensionsChanged"
Constant value for the
cropDimensionsChanged event. | ImageCropper | ||
| CROP_POSITION_CHANGED : String = "cropPositionChanged"
Constant value for the
cropPositionChanged event. | ImageCropper | ||
| CROP_RECT_CHANGED : String = "cropRectChanged"
Constant value for the
cropRectChanged event. | ImageCropper | ||
| SOURCE_IMAGE_LOAD_ERROR : String = "sourceImageLoadError"
Constant value for the
sourceImageLoadError event. | ImageCropper | ||
| SOURCE_IMAGE_LOADING : String = "sourceImageLoading"
Constant value for the
sourceImageLoading event. | ImageCropper | ||
| SOURCE_IMAGE_READY : String = "sourceImageReady"
Constant value for the
sourceImageReady event. | ImageCropper | ||
| VERSION : Number = 1.0
The version number of the ImageCropper component.
| ImageCropper | ||
| backgroundAlpha | property |
backgroundAlpha:Number [read-write]The level of transparency (0 to 1) for the component's background. The component background will be visible only when an image does not entirely fill the component area.
The default value is 0.
public function get backgroundAlpha():Number
public function set backgroundAlpha(value:Number):void
| backgroundColor | property |
backgroundColor:uint [read-write]The background color for the component. The component background will be visible only when an image does not entirely fill the component area.
The default value is 0x00000000.
public function get backgroundColor():uint
public function set backgroundColor(value:uint):void
| constrainToAspectRatio | property |
constrainToAspectRatio:Boolean [read-write]
If set to true then the cropping rectangle will always maintain the aspect ratio that was active when the constrainToAspectRatio property was set.
For example, suppose the cropping rectangle has dimensions of 200 x 100 (an aspect ratio of 2:1). If constrainToAspectRatio is set to true then
dragging any of the handles will cause the cropping rectangle to maintain a 2:1 relationship between the width and the height. If dragging a handle causes the width to increase
to 400, then the height of the cropping rectangle will be adjusted to 200. If the height is changed to 50, then the width will be adjusted to 100.
Enabling constrainToAspectRatio can be useful if you wish to crop an image so that it can be scaled to fixed dimensions without distortion. For example,
suppose that you want to crop an image so that it will exactly fit a target area that is 400 pixels wide and 600 pixels high. Since the target area has an aspect ratio of 2:3
you'll want to call the setCropRect method to set an initial cropping rectangle with dimensions that conform to the target aspect ratio. In this case, let's say that
we set the cropping rectangle to a width of 80 and to a height of 120 (a ratio of 2:3). Now when we set constrainToAspectRatio
to true the cropping rectangle will always maintain a width to height ratio of 2:3. Once the portion of the image to crop is selected, all that needs to be
done is to retrieve the BitmapData from the croppedBitmapData parameter and then scale the BitmapData to the final size (400 x 600).
Setting constrainToAspectRatio to false allows the width and height of the cropping rectangle to be adjusted independently.
The default value is false.
public function get constrainToAspectRatio():Boolean
public function set constrainToAspectRatio(value:Boolean):void
| croppedBitmapData | property |
croppedBitmapData:BitmapData [read-only]
The cropped source image as a BitmapData object. The cropped portion of the source image is defined by the position and the dimensions of the cropping rectangle.
public function get croppedBitmapData():BitmapData
| enabled | property |
enabled:Boolean [read-write]
Whether the component can accept user interaction or changes to properties. If the enabled property is set to false then the cropping rectangle is removed
and all component properties become read-only (except for the enabled property). In addition, calls to the setCropRect method are ignored.
The component may be re-enabled by setting the enabled property to true.
The default value is true.
public function get enabled():Boolean
public function set enabled(value:Boolean):void
| handleAlpha | property |
handleAlpha:Number [read-write]The level of transparency (0 to 1) for the four corner handles of the cropping rectangle.
The default value is 0.5.
public function get handleAlpha():Number
public function set handleAlpha(value:Number):void
| handleColor | property |
handleColor:uint [read-write]The color used for the four corner handles of the cropping rectangle.
The default value is 0x00FF0000.
public function get handleColor():uint
public function set handleColor(value:uint):void
| handleSize | property |
handleSize:Number [read-write]The size of each of the four corner handles of the cropping rectangle. The minimum allowed handle size is 3.
The default value is 10.
public function get handleSize():Number
public function set handleSize(value:Number):void
| maskAlpha | property |
maskAlpha:Number [read-write]The level of transparency (0 to 1) for the mask that is used to indicate the non-selected portion of the cropped image. The mask will only be visible when the dimensions of the cropping rectangle are smaller than the dimensions of the image.
The default value is 0.3.
public function get maskAlpha():Number
public function set maskAlpha(value:Number):void
| maskColor | property |
maskColor:uint [read-write]The color of the mask used to indicate the non-selected portion of the cropped image. The mask will be visible only when the dimensions of the cropping rectangle are smaller than the dimensions of the image.
The default value is 0x00FF0000.
public function get maskColor():uint
public function set maskColor(value:uint):void
| outlineAlpha | property |
outlineAlpha:Number [read-write]The level of transparency (0 to 1) used for the single pixel outline drawn around the cropping rectangle and around the four corner handles of the cropping rectangle.
The default value is 0.
public function get outlineAlpha():Number
public function set outlineAlpha(value:Number):void
| outlineColor | property |
outlineColor:uint [read-write]The color used for single pixel outline drawn around the cropping rectangle and around the four corner handles of the cropping rectangle.
The default value is 0x00FFFFFF.
public function get outlineColor():uint
public function set outlineColor(value:uint):void
| sourceImage | property |
sourceImage:Object [read-write]
Either a String that contains a URL pointing to an image or a BitmapData object that contains an image.
If a URL String is assigned to this parameter, then a sourceImageLoading event will be dispatched and the
component will begin loading the referenced image. Once the image has been loaded then a sourceImageReady event will be dispatched
and the image will be displayed in the component. If an error occurs while loading the image, then a sourceImageLoadError event will be dispatched
If a BitmapData object is assigned to this parameter, then a sourceImageReady event will immediately be dispatched
and the image contained in the BitmapData object will be displayed in the component.
When reading this parameter an Object will be returned of type String or of type BitmapData, depending upon what type of
object was last assigned to the sourceImage parameter. If no assignment was made to the sourceImage parameter, then null is returned.
public function get sourceImage():Object
public function set sourceImage(value:Object):void
| ImageCropper | () | constructor |
public function ImageCropper()Class constructor.
| destroy | () | method |
public function destroy():void
Call this method to dereference resources when the ImageCropper component is no longer needed. For example, if the ImageCropper component is
used in a pop-up window and the window is closed, call destroy when removing the window.
| getCropRect | () | method |
public function getCropRect(componentRelative:Boolean = false, roundValues:Boolean = false):Rectangle
Returns the position and the dimensions of the cropped portion of the image as a Rectangle.
componentRelative:Boolean (default = false) — If set to true then the Rectangle returned represents the position and dimensions of the cropping rectangle in the component.
If set to false then the Rectangle returned represents the position and dimensions of the crop area in the source image.
|
|
roundValues:Boolean (default = false) — If set to true then all values in the returned Rectangle are rounded to integer values.
|
Rectangle — The position and dimensions of the crop area relative to the component (if componentRelative is true) or relative to the source image
(if componentRelative is false). If a cropping rectangle has not been defined, then null will be returned.
|
| setCropRect | () | method |
public function setCropRect(width:Number = 0, height:Number = 0, x:Number = -1, y:Number = -1, componentRelative:Boolean = false):voidThis method defines the position and the dimensions of the cropping rectangle within the component.
Note that values specified for the width, height, x and y parameters can be relative to either the component (if componentRelative is true)
or to the source image (if componentRelative is false).
For example, suppose the component has dimensions of 250x250 but the source image has dimensions of 500x500. In this case the component will automatically scale the source image so that it fits within
the component area. If componentRelative is set to false then setting a cropping rectangle with dimensions of 100x50 will result in a cropping rectangle being drawn in the component
area with dimensions of 50x25 (i.e. the cropping rectangle dimensions are relative to the source image). If componentRelative is set to true then the cropping rectangle will be drawn with
dimensions of 100x50 (i.e. the cropping rectangle dimensions are relative to the component area).
If the width or the height parameter is assigned a value of zero, then the cropping rectangle will be set to the full size of the image and any values specified for
the x and y parameters will be ignored.
width:Number (default = 0) — Sets the width of the cropping rectangle. Setting width to zero will result in both the width and the height of the cropping rectangle being set to the size of the image displayed in the component.
|
|
height:Number (default = 0) — Sets the height of the cropping rectangle. Setting height to zero will result in both the width and the height of the cropping rectangle being set to the size of the image displayed in the component.
|
|
x:Number (default = -1) — Sets the horizontal position of the cropping rectangle. Setting x to -1 will result in the cropping rectangle being centered vertically and horizontally in the component.
|
|
y:Number (default = -1) — Sets the vertical position of the cropping rectangle. Setting y to -1 will result in the cropping rectangle being centered vertically and horizontally in the component.
|
|
componentRelative:Boolean (default = false) — When set to true then the width, height, x and y parameters are relative to the image
displayed in the component. When componentRelative is set to false then the parameters are relative to the source image. If the source image completely fits within
the component without scaling, then componentRelative in essence has no effect since the component image and the source image are identical.
|
| cropConstraintChanged | event |
This event is dispatched whenever constrainToAspectRatio is set to true and the component alters the aspect ratio of the cropping rectangle.
One situation where the component will alter the aspect ratio of the cropping rectangle is if the cropping rectangle handle size is increased and the cropping rectangle is
not large enough to contain the increased size of the handles. The other situation where the component will alter the aspect ratio of the cropping rectangle is when the cropping rectangle is initialized following
a call to setCropRect and the parameters passed to setCropRect necessitate that the component change the cropping rectangle in order for it to be properly displayed within the component
(e.g., the coordinates passed for the cropping rectangle place part of the cropping rectangle outside of the component's display area).
| cropConstraintDisabled | event |
If constrainToAspectRatio is set to true and a call to setCropRect is executed with a width or height value less than or equal to zero,
then constrainToAspectRatio will be disabled and this event will be dispatched.
| cropDimensionsChanged | event |
This event is dispatched whenever the component alters the dimensions of the cropping rectangle.
If the cropping rectangle handle size is increased by setting the handleSize property and there is not enough room within the cropping rectangle to contain the larger handles,
then the component will increase the size of the cropping rectangle and dispatch this event.
This event is also dispatched if the width and height of the cropping rectangle are specified in a call to setCropRect but the cropping rectangle cannot be properly displayed in the component
using the specified dimensions. In this case the component will adjust the dimensions of the cropping rectangle and dispatch the cropDimensionsChanged event.
| cropPositionChanged | event |
This event is dispatched whenever the component alters the position of the cropping rectangle.
If the cropping rectangle handle size is increased by setting the handleSize property and there is not enough room within the cropping rectangle to contain the larger handles,
then the component will increase the size of the cropping rectangle. If the position of the cropping rectangle changes when its size is increased, then this event will be dispatched.
This event is also dispatched if the position of the cropping rectangle is specified in a call to setCropRect but the cropping rectangle cannot be properly displayed in the component
at the specified position. In this case the component will adjust the position of the cropping rectangle and dispatch the cropPositionChanged event.
| cropRectChanged | event |
This event is dispatched whenever the cropping rectangle is resized or repositioned using the mouse.
| sourceImageLoadError | event |
This event is dispatched if an I/O error occurs while loading an image from a URL.
| sourceImageLoading | event |
This event is dispatched when the component begins loading an image from a URL.
| sourceImageReady | event |
This event is dispatched when the component has completed loading an image from a URL or when a BitmapData object is specified for the sourceImage parameter.
| CROP_CONSTRAINT_CHANGED | constant |
public const CROP_CONSTRAINT_CHANGED:String = "cropConstraintChanged"
Constant value for the cropConstraintChanged event.
| CROP_CONSTRAINT_DISABLED | constant |
public const CROP_CONSTRAINT_DISABLED:String = "cropConstraintDisabled"
Constant value for the cropConstraintDisabled event.
| CROP_DIMENSIONS_CHANGED | constant |
public const CROP_DIMENSIONS_CHANGED:String = "cropDimensionsChanged"
Constant value for the cropDimensionsChanged event.
| CROP_POSITION_CHANGED | constant |
public const CROP_POSITION_CHANGED:String = "cropPositionChanged"
Constant value for the cropPositionChanged event.
| CROP_RECT_CHANGED | constant |
public const CROP_RECT_CHANGED:String = "cropRectChanged"
Constant value for the cropRectChanged event.
| SOURCE_IMAGE_LOAD_ERROR | constant |
public const SOURCE_IMAGE_LOAD_ERROR:String = "sourceImageLoadError"
Constant value for the sourceImageLoadError event.
| SOURCE_IMAGE_LOADING | constant |
public const SOURCE_IMAGE_LOADING:String = "sourceImageLoading"
Constant value for the sourceImageLoading event.
| SOURCE_IMAGE_READY | constant |
public const SOURCE_IMAGE_READY:String = "sourceImageReady"
Constant value for the sourceImageReady event.
| VERSION | constant |
public const VERSION:Number = 1.0The version number of the ImageCropper component.