View comments | RSS feed

getPixel32 (BitmapData.getPixel32 method)

public getPixel32(x:Number, y:Number) : Number

Returns an ARGB color value that contains alpha channel data and RGB data. This method is similar to the getPixel() method, which returns an RGB color without alpha channel data.

Availability: ActionScript 1.0; Flash Player 8

Parameters

x:Number - The x position of the pixel.

y:Number - The y position of the pixel.

Returns

Number - A number that represent an ARGB pixel value. If the (x, y) coordinates are outside the bounds of the image, 0 is returned. If the bitmap was created as an opaque bitmap and not a transparent one, then this method will return an error code of -1.

Example

The following example uses the getPixel32() method to retrieve the ARGB value of a pixel at a specific x and y position:

import flash.display.BitmapData;

var myBitmapData:BitmapData = new BitmapData(100, 80, true, 0xFFAACCEE);

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

var alpha:String = (myBitmapData.getPixel32(0, 0) >> 24 & 0xFF).toString(16);
trace(">> alpha: " + alpha); // ff

var red:String = (myBitmapData.getPixel32(0, 0) >> 16 & 0xFF).toString(16);
trace(">> red: " + red); // aa

var green:String = (myBitmapData.getPixel32(0, 0) >> 8 & 0xFF).toString(16);
trace(">> green: " + green); // cc

var blue:String = (myBitmapData.getPixel32(0, 0) & 0xFF).toString(16);
trace(">> blue: " + blue); // ee

trace("0x" + alpha + red + green + blue); // 0xffaaccee

See also

getPixel (BitmapData.getPixel method)


Version 8

Comments


katopz@sleepydesign.com said on Mar 31, 2006 at 1:12 AM :
import flash.display.BitmapData;
var out_bmp:BitmapData = new BitmapData(10,10,true,0x33FF3300);
trace("get : 0x"+out_bmp.getPixel(0, 0).toString(16)+" ("+out_bmp.getPixel(0, 0)+")");
trace("get32 : 0x"+out_bmp.getPixel32(0, 0).toString(16)+" ("+out_bmp.getPixel32(0, 0)+")");


the result is weird (must be "0x33FF3300" but...)
------------------------------------------------------------
get : 0xff3200 (16724480)
get32 : 0x33ff3200 (872362496)
------------------------------------------------------------
this is a bug or something?
panell said on Sep 27, 2006 at 7:25 AM :
sometimes function getPixel32 returns 'short values'. ex if you have color A20F63 it will return A2F63 becouse green 0F will be returned as F

So if you want to get 6 signs colors as in HTML format you shoul:

var alpha:String = (bdSource.getPixel32(i, _rowToCopy) >> 24 & 0xFF).toString(16)
var red:String = (bdSource.getPixel32(i, _rowToCopy) >> 16 & 0xFF).toString(16)
var green:String = (bdSource.getPixel32(i, _rowToCopy) >> 8 & 0xFF).toString(16)
var blue:String = (bdSource.getPixel32(i, _rowToCopy) & 0xFF).toString(16)

//and now check if color is short
if(alpha.length == 1)
alpha = "0" + alpha
if(red.length == 1)
red = "0" + red
if(green.length == 1)
green = "0" + green
if(blue.length == 1)
blue = "0" + blue
evanwingerden said on Nov 16, 2006 at 1:02 PM :
@ katopz

No that is not a bug. The extra values returned by the getPixel32 are that of the alpha channel, something which the getPixel function lacks.

Obviously only use getPixel32 for bitmaps that utilize an alpha channel.

 

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

Current page: http://livedocs.adobe.com/flash/8/main/00001956.html