compare (BitmapData.compare method)

public compare(otherBitmapData:BitmapData) : Object

Compares two BitmapData objects. If the two BitmapData objects have the same dimensions (width and height), the method returns a new BitmapData object, in which each pixel is the "difference" between the pixels in the two source objects:

For example, consider the following two BitmapData objects:

var bmd1:BitmapData = new BitmapData(50, 50, true, 0xFFFF0000);
var bmd2:BitmapData = new BitmapData(50, 50, true, 0xCCFFAA00);
var diffBmpData:BitmapData = bmd1.compare(bmd2);

Note: The colors used to fill the two BitmapData objects have slightly different RGB values (0xFF0000 and 0xFFAA00). The result of the compare() method is a new BitmapData object with each pixel showing the difference in the RGB values between the two bitmaps.

Consider the following two BitmapData objects, in which the RGB colors are the same, but the alpha values are different:

var bmd1:BitmapData = new BitmapData(50, 50, true, 0xFFFFAA00);
var bmd2:BitmapData = new BitmapData(50, 50, true, 0xCCFFAA00);
var diffBmpData:BitmapData = bmd1.compare(bmd2);

The result of the compare() method is a new BitmapData object with each pixel showing the difference in the alpha values between the two bitmaps.

If the BitmapData objects are equivalent (with the same width, height, and identical pixel values), the method returns the number 0.

If no argument is passed or if the argument is not a BitmapData object, the method returns -1.

If either BitmapData object has been disposed of, the method returns -2.

If the widths of the BitmapData objects are not equal, but the heights are the same, the method returns the number -3.

If the heights of the BitmapData objects are not equal, but the widths are the same, the method returns the number -4.

The following example compares two Bitmap objects with different widths (50 and 60):

var bmd1:BitmapData = new BitmapData(100, 50, false, 0xFFFF0000);
var bmd2:BitmapData = new BitmapData(100, 60, false, 0xFFFFAA00);
trace(bmd1.compare(bmd2)); // -3

Availability: ActionScript 1.0; Flash Player 9

Parameters

otherBitmapData:BitmapData - The BitmapData object to compare with the source BitmapData object.

Returns

Object - If the two BitmapData objects have the same dimensions (width and height), the method returns a new BitmapData object that has the difference between the two objects (see the main discussion). If the BitmapData objects are equivalent, the method returns the number 0. If no argument is passed or if the argument is not a BitmapData object, the method returns -1. If either BitmapData object has been disposed of, the method returns -2. If the widths of the BitmapData objects are not equal, the method returns the number -3. If the heights of the BitmapData objects are not equal, the method returns the number -4.


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/00001398.html