draw (BitmapData.draw method)

public draw(source:Object, [matrix:Matrix], [colorTransform:ColorTransform], [blendMode:Object], [clipRect:Rectangle], [smooth:Boolean]) : Void

Draws a source image or movie clip onto a destination image, using the Flash Player vector renderer. You can specify a transformation matrix, a ColorTransform object, a blend mode setting, and a destination Rectangle object to control how the rendering performs. Optionally, you can specify whether the bitmap should be smoothed when scaled. This works only if the source object is a BitmapData object.

This method directly corresponds to how objects are drawn using the standard vector renderer for objects in the authoring tool interface.

A source MovieClip object does not use any of its on-stage transformations for this call. It is treated as it exists in the library or file, with no matrix transform, no color transform, and no blend mode. If you want to draw the movie clip by using its own transform properties, you can use its Transform object to pass the various transformation properties.

Availability: ActionScript 1.0; Flash Player 8

Parameters

source:Object - The BitmapData object to draw.

matrix:Matrix [optional] - A Matrix object used to scale, rotate, or translate the coordinates of the bitmap. If no object is supplied, the bitmap image will not be transformed. Set this parameter to an identity matrix, created using the default new Matrix() constructor, if you must pass this parameter but you do not want to transform the image.

colorTransform:ColorTransform [optional] - A ColorTransform object that you use to adjust the color values of the bitmap. If no object is supplied, the bitmap image's colors will not be transformed. Set this parameter to a ColorTransform object created using the default new ColorTransform() constructor, if you must pass this parameter but you do not want to transform the image.

blendMode:Object [optional] - A blend mode setting for the transformation. This parameter can be either an integer (from 1 through 14) or a string (such as "normal" or "darken"). For a list of valid blendMode values, see the blendMode property of the MovieClip class.

clipRect:Rectangle [optional] - A Rectangle object. If you do not supply this value, no clipping occurs.

smooth:Boolean [optional] - A Boolean value that determines whether a BitmapData object is smoothed when scaled or rotated, due to a scaling or rotation in the matrix parameter. The default value is false. The smoothing parameter only applies if the source parameter is a BitmapData object. With smoothing set to false, the rotated or scaled BitmapData image can appear pixelated or jagged. For example, the following two images use the same BitmapData object for the source parameter, but the smoothing parameter is set to true on the left and false on the right:



Drawing a bitmap with smoothing set to true takes longer than doing so with smoothing set to false.

Example

The following example shows how to draw from a source MovieClip instance to a BitmapData object.

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;

var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(myBitmapData, this.getNextHighestDepth());

var mc_2:MovieClip = createRectangle(50, 40, 0xFF0000);
mc_2._x = 101;

var myMatrix:Matrix = new Matrix();
myMatrix.rotate(Math.PI/2);

var translateMatrix:Matrix = new Matrix();
translateMatrix.translate(70, 15);

myMatrix.concat(translateMatrix);

var myColorTransform:ColorTransform = new ColorTransform(0, 0, 1, 1, 0, 0, 255, 0);
var blendMode:String = "normal";

var myRectangle:Rectangle = new Rectangle(0, 0, 100, 80);
var smooth:Boolean = true;

mc_1.onPress = function() {
    myBitmapData.draw(mc_2, myMatrix, myColorTransform, blendMode, myRectangle, smooth);
}

function createRectangle(width:Number, height:Number, color:Number):MovieClip {
    var depth:Number = this.getNextHighestDepth();
    var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}

See also

blendMode (MovieClip.blendMode property), ColorTransform (flash.geom.ColorTransform), Matrix (flash.geom.Matrix), Rectangle (flash.geom.Rectangle)


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001402.html