View comments | RSS feed

merge (BitmapData.merge method)

public merge(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, redMult:Number, greenMult:Number, blueMult:Number, alphaMult:Number) : Void

Performs per-channel blending from a source image to a destination image. The following formula is used for each channel:

new red dest = (red source * redMult) + (red dest * (256 - redMult) / 256;

The redMult, greenMult, blueMult, and alphaMult values are the multipliers used for each color channel. Their valid range is from 0 to 256.

Availability: ActionScript 1.0; Flash Player 8

Parameters

sourceBitmap:BitmapData - The input bitmap image to use. The source image can be a different BitmapData object, or it can refer to the current BitmapData object.

sourceRect:Rectangle - A rectangle that defines the area of the source image to use as input.

destPoint:Point - The point within the destination image (the current BitmapData instance) that corresponds to the upper-left corner of the source rectangle.

redMult:Number - A number by which to multiply the red channel value.

greenMult:Number - A number by which to multiply the green channel value.

blueMult:Number - A number by which to multiply the blue channel value.

alphaMult:Number - A number by which to multiply the alpha transparency value.

Example

The following example shows how to merge part of one BitmapData with another.

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bitmapData_1:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);
var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);

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

var mc_2:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_2.attachBitmap(bitmapData_2, this.getNextHighestDepth());
mc_2._x = 101;

mc_1.onPress = function() {
    bitmapData_1.merge(bitmapData_2, new Rectangle(0, 0, 50, 40), new Point(25, 20), 128, 0, 0, 0);
}

Flash CS3


Comments


Rothrock said on Jun 7, 2007 at 1:05 PM :
Has anybody noticed that the parens in the formula are not balanced? Also I haven't been able to come up with a balance that doesn't give really wrong numbers for the answer.
Rothrock said on Jun 7, 2007 at 1:09 PM :
Okay. I think it is supposed to be this:

new red dest = (red source * redMult) + (red dest * (256 - redMult) )) / 256;
tderich said on Sep 18, 2007 at 1:38 PM :
See AS3 BitmapData.merge() for updates:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#merge()

 

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

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