API Docs for: 最后更新日期:2014年8月25日
Google搜索   
Show:

LBitmapData Class

Extends LObject

Available since 1.0.0

Creates a BitmapData object with a specified width and height. The BitmapData class lets you work with the data (pixels) of a Bitmap object . You can use the methods of the BitmapData class to create arbitrarily sized an Image object. And You can use an Image object with LLoader。

Constructor

LBitmapData

(
  • image
  • x
  • y
  • width
  • height
  • dataType
)
public

Defined in display/LBitmapData.js:1

Available since 1.0.0

Parameters:

  • image Image

    The Image object。

  • x Float

    The x coordinate of the image.(Optional).

  • y Float

    The y coordinate of the image.(Optional).

  • width Float

    The width of the bitmap image in pixels.(Optional).

  • height Float

    The height of the bitmap image in pixels.(Optional).

  • dataType String

    You can use the type with LBitmapData.DATA_IMAGE(Image object)or LBitmapData.DATA_CANVAS(Canvas object)。(Optional).

Example:

Linit(50, "mylegend", 800, 480, main);
function main () {
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("lufylegend.js.png", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.currentTarget);  
    var bitmap = new LBitmap(bitmapdata);
    addChild(bitmap);

    var bitmapdata2 = new LBitmapData("#FF0000", 0, 0, 100, 100);
    var bitmap2 = new LBitmap(bitmapdata2);
    bitmap2.x = 200;
    addChild(bitmap2);
}

Methods

callParent

(
  • functionName
  • arguments
)
public

Inherited from LObject: main/LObject.js:22

Available since 1.6.0

call the method of parent。

Parameters:

  • functionName String

    function's name

  • arguments Array

    Fixed value : arguments

Example:

function funA(){
    LExtends(this,LObject,[]);
}
funA.prototype.myName = function(){
    return "AAA";
}
function funB(){
    LExtends(this,funA,[]);
}
funB.prototype.myName = function(){
    return "BBB";
}
function funC(){
    LExtends(this,funA,[]);
}
funC.prototype.myName = function(){
    return this.callParent("myName",arguments);
}
LInit(1000/50,"legend",800,150,main);
function main(){
    LGlobal.setDebug(true);
    var objB = new funB();
    trace(objB.myName());//BBB
    var objC = new funC();
    trace(objC.myName());//AAA
}

clone

() LBitmapData public

Defined in display/LBitmapData.js:216

Available since 1.8.2

Returns a new BitmapData object that is a clone of the original instance with an exact copy of the contained bitmap.

Returns:

LBitmapData:

A new BitmapData object that is identical to the original.

Example:

var bmd1 = new LBitmapData("#FF0000", 0, 0, 100, 100);
var bm1 = new LBitmap(bmd1);
addChild(bm1);

var bmd2 = bmd1.clone();
var bm2 = new LBitmap(bmd2);
bm2.x = 120;
addChild(bm2);

colorTransform

(
  • rect
  • colorTransform
)
public

Defined in display/LBitmapData.js:616

Available since 1.9.4

This method copies a rectangular area of a source image to a rectangular area of the same size at the destination point of the destination LBitmapData object.

Conditions:The data type of the LBitmapData is Canvas object。

Parameters:

  • rect LRectangle

    A LRectangle object that defines the area of the image in which the LColorTransform object is applied.

  • colorTransform LColorTransform

    A LColorTransform object that describes the color transformation values to apply.

Example:

LInit(50, "legend", 800, 480, main);
function main () {
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapData = new LBitmapData(event.target, 0, 0, 240, 240, LBitmapData.DATA_CANVAS);
    var rect = new LRectangle(50, 50, 90, 90);
    var colorTransform = new LColorTransform(0.5, 0.7, 0.4, 1, 0, 0, 0, 0);
    bitmapData.colorTransform(rect, colorTransform);
    var bitmap = new LBitmap(bitmapData);
    addChild(bitmap);
}

copyPixels

(
  • sourceBitmapData
  • sourceRect
  • destPoint
)
public

Defined in display/LBitmapData.js:658

Available since 1.9.4

This method copies a rectangular area of a source image to a rectangular area of the same size at the destination point of the destination LBitmapData object.

Conditions:The data type of the LBitmapData is Canvas object。

Parameters:

  • sourceBitmapData LBitmapData

    The input bitmap image from which to copy pixels. The source image can be a different LBitmapData instance, or it can refer to the current LBitmapData instance.

  • sourceRect LRectangle

    A rectangle that defines the area of the source image to use as input.

  • destPoint LPoint

    The destination point that represents the upper-left corner of the rectangular area where the new pixels are placed.

Example:

LInit(50, "legend", 800, 480, main);
function main () {
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapData = new LBitmapData(event.target);
    bitmapData2 = new LBitmapData(null, 0, 0, 240, 240, LBitmapData.DATA_CANVAS);
    bitmapData2.copyPixels(bitmapData, new LRectangle(0, 0, 240, 240), new LPoint(0,0));
    bitmapData2.copyPixels(bitmapData, new LRectangle(50, 50, 100, 100), new LPoint(0,50));
    bitmapData2.copyPixels(bitmapData, new LRectangle(100, 50, 100, 100), new LPoint(50,150));

    var bitmap = new LBitmap(bitmapData);
    addChild(bitmap);

    var bitmap2 = new LBitmap(bitmapData2);
    bitmap2.y = 250;
    addChild(bitmap2);
}

draw

(
  • [source]
  • matrix
  • colorTransform
  • blendMode
  • clipRect
)
public

Defined in display/LBitmapData.js:529

Available since 1.7.7

Draws the source display object onto the bitmap image, using the Flash runtime vector renderer.

Parameters:

  • [source] LDisplayObject | LBitmapData optional

    The display object or LBitmapData object to draw to the LBitmapData object.

  • matrix LMatrix

    A LMatrix object used to scale, rotate, or translate the coordinates of the bitmap. If you do not want to apply a matrix transformation to the image, set this parameter to an identity matrix, created with the default new LMatrix() constructor, or pass a null value.

  • colorTransform LColorTransform

    A ColorTransform object that you use to adjust the color values of the bitmap. If no object is supplied, the bitmap image's colors are not transformed. If you must pass this parameter but you do not want to transform the image, set this parameter to a ColorTransform object created with the default new ColorTransform() constructor.

    Try it »

  • blendMode String

    A string value, from the flash.display.BlendMode class, specifying the blend mode to be applied to the resulting bitmap.

    Try it »

  • clipRect LRectangle

    A Rectangle object that defines the area of the source object to draw. If you do not supply this value, no clipping occurs and the entire source object is drawn.

    Try it »

Example:

var layer = new LSprite();
layer.graphics.drawRect(1, "#000000", [0, 0, 100, 100], true, "#000000");
layer.graphics.drawRect(1, "#FF0000", [100, 0, 100, 100], true, "#FF0000");
addChild(layer);

var bitmapData = new LBitmapData(null, 0, 0, 500, 400);
bitmapData.draw(layer);
var bitmap = new LBitmap(bitmapData);
bitmap.y = 150;
addChild(bitmap);

getPixel

(
  • x
  • y
  • colorType
)
Array public

Defined in display/LBitmapData.js:249

Available since 1.5.1

Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y).

Parameters:

  • x Int

    The x position of the pixel.

  • y Int

    The y position of the pixel.

  • colorType String

    the color type. [number|array].(Optional).

Returns:

Array:

A array that represents an RGB pixel value.

Example:

var bitmapData = new LBitmapData(event.currentTarget);
bitmapData2 = new LBitmapData(null, 0, 0, 500, 400);
var img, imgs = [], arr;
bitmapData.lock();
for (var i = 0; i < 50; i++) {
     arr = [];
     for (var j = 0; j < 50; j++) {
        img = bitmapData.getPixel(100 + i, 100 + j);
        arr.push(img);
    }
    imgs.push(arr);
}
bitmapData.unlock();
bitmapData2.lock();
for (var i = 0; i < 50; i++) {
    arr = imgs[i];
    for (var j = 0; j < 50; j++) {
        img = arr[j];
        bitmapData2.setPixel(i, j, img);
    }
}
bitmapData2.unlock();
var bitmap = new LBitmap(bitmapData);
addChild(bitmap);
var bitmap2 = new LBitmap(bitmapData2);
bitmap2.x = 250;
addChild(bitmap2);

getPixels

(
  • rect
)
Array public

Defined in display/LBitmapData.js:371

Available since 1.5.1

Generates an array from a rectangular region of pixel data.

Parameters:

  • rect LRectangle

    A rectangular area in the current BitmapData object.

Returns:

Array:

the pixels in the given Rectangle.

Example:

var bitmapData = new LBitmapData(event.currentTarget);
bitmapData2 = new LBitmapData(null, 0, 0, 500, 400);
var img = bitmapData.getPixels(new LRectangle(75, 50, 100, 100));
bitmapData2.lock();
bitmapData2.setPixels(new LRectangle(50, 30, 50, 50), img);
bitmapData2.setPixels(new LRectangle(100, 30, 50, 50), img);
bitmapData2.setPixels(new LRectangle(150, 30, 50, 50), img);
bitmapData2.setPixels(new LRectangle(200, 30, 50, 50), img);
bitmapData2.unlock(); 

var bitmap = new LBitmap(bitmapData);
addChild(bitmap);

var bitmap2 = new LBitmap(bitmapData2);
bitmap2.y = 250;
addChild(bitmap2);

lock

() public

Defined in display/LBitmapData.js:507

Available since 1.5.1

Locks an image so that any objects that reference the BitmapData object, such as Bitmap objects, are not updated when this BitmapData object changes.

putPixels

(
  • rect
  • data
)
public

Defined in display/LBitmapData.js:472

Available since 1.9.1

Sets a single pixel of a LBitmapData object.

Sets rect pixels of a LBitmapData object. Conditions:

1,The data type of the LBitmapData is Canvas object。

2,Operate only once or a small number,Do not using setPixel, setPixels, getPixel, getPixels at the same time。

You can use putPixels instead setPixels, but fast,and do not need to lock and unlock.

Parameters:

  • rect LRectangle

    Specifies the rectangular region of the BitmapData object.

  • data Array

    the values to be used in the rectangular region.(ImageData object)

Example:

var bitmapData = new LBitmapData(event.currentTarget);
bitmapData2 = new LBitmapData(null, 0, 0, 500, 400,LBitmapData.DATA_CANVAS);
bitmapData.lock();
var img = bitmapData.getPixels(new LRectangle(75, 50, 100, 100));
bitmapData.unlock();

bitmapData2.putPixels(new LRectangle(50, 30, 50, 50), img);

var bitmap = new LBitmap(bitmapData);
addChild(bitmap);

var bitmap2 = new LBitmap(bitmapData2);
bitmap2.y = 250;
addChild(bitmap2);

setCoordinate

(
  • x
  • y
)
public

Defined in display/LBitmapData.js:191

Available since 1.0.0

Change coordinate of the Image's visual range

Parameters:

  • x Float

    The x coordinate of the image.

  • y Float

    The y coordinate of the image.

Example:

var bitmapdata1 = new LBitmapData(event.currentTarget, 20, 20, 100, 100);
var bitmap1 = new LBitmap(bitmapdata1);
addChild(bitmap1);

var bitmapdata2 = new LBitmapData(event.currentTarget, 20, 20, 100, 100);
bitmapdata2.setCoordinate(100, 100);
var bitmap2 = new LBitmap(bitmapdata2);
bitmap2.x = 120;
addChild(bitmap2);

setPixel

(
  • x
  • y
  • data
)
Array public

Defined in display/LBitmapData.js:306

Available since 1.5.1

Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y).

Parameters:

  • x Int

    The x position of the pixel whose value changes.

  • y Int

    The y position of the pixel whose value changes.

  • data Array

    The resulting pixel data for the pixel.

Returns:

Array:

A array that represents an RGB pixel value.

Example:

var bitmapData = new LBitmapData(event.currentTarget);
bitmapData2 = new LBitmapData(null, 0, 0, 500, 400);
var img, imgs = [], arr;
bitmapData.lock();
for (var i = 0; i < 50; i++) {
     arr = [];
     for (var j = 0; j < 50; j++) {
        img = bitmapData.getPixel(100 + i, 100 + j);
        arr.push(img);
    }
    imgs.push(arr);
}
bitmapData.unlock();
bitmapData2.lock();
for (var i = 0; i < 50; i++) {
    arr = imgs[i];
    for (var j = 0; j < 50; j++) {
        img = arr[j];
        bitmapData2.setPixel(i, j, img);
    }
}
bitmapData2.unlock();
var bitmap = new LBitmap(bitmapData);
addChild(bitmap);
var bitmap2 = new LBitmap(bitmapData2);
bitmap2.x = 250;
addChild(bitmap2);

setPixels

(
  • rect
  • data
)
public

Defined in display/LBitmapData.js:408

Available since 1.5.1

Sets rect pixels of a LBitmapData object.

Parameters:

  • rect LRectangle

    Specifies the rectangular region of the BitmapData object.

  • data Array

    the values to be used in the rectangular region.(ImageData object | String"#000000" | Number0x000000)

Example:

var bitmapData = new LBitmapData(event.currentTarget);
bitmapData2 = new LBitmapData(null, 0, 0, 500, 400);
var img = bitmapData.getPixels(new LRectangle(75, 50, 100, 100));
bitmapData2.lock();
bitmapData2.setPixels(new LRectangle(50, 30, 50, 50), img);
bitmapData2.setPixels(new LRectangle(100, 30, 50, 50), img);
bitmapData2.setPixels(new LRectangle(150, 30, 50, 50), img);
bitmapData2.setPixels(new LRectangle(200, 30, 50, 50), img);
bitmapData2.unlock(); 

var bitmap = new LBitmap(bitmapData);
addChild(bitmap);

var bitmap2 = new LBitmap(bitmapData2);
bitmap2.y = 250;
addChild(bitmap2);

setProperties

(
  • x
  • y
  • width
  • height
)
public

Defined in display/LBitmapData.js:162

Available since 1.0.0

Change the Image's visual range

Parameters:

  • x Float

    The x coordinate of the image.

  • y Float

    The y coordinate of the image.

  • width Float

    The width of the bitmap image in pixels.

  • height Float

    The height of the bitmap image in pixels.

Example:

var bitmapdata1 = new LBitmapData(event.currentTarget, 0, 0, 200, 200);
var bitmap1 = new LBitmap(bitmapdata1);
addChild(bitmap1);

var bitmapdata2 = new LBitmapData(event.currentTarget);
bitmapdata2.setProperties(50, 100, 200, 50);
var bitmap2 = new LBitmap(bitmapdata2);
bitmap2.x = 240;
addChild(bitmap2);

unlock

() public

Defined in display/LBitmapData.js:518

Available since 1.5.1

Unlocks an image so that any objects that reference the BitmapData object, such as Bitmap objects, are updated when this BitmapData object changes.

Properties

dataType

String public

Defined in display/LBitmapData.js:77

Available since 1.8.8

data type, LBitmapData.DATA_IMAGE(Image object)or LBitmapData.DATA_CANVAS(Canvas object)。

height

Float public

Defined in display/LBitmapData.js:69

Available since 1.0.0

The height of the bitmap image in pixels.

LBitmapData.DATA_CANVAS

String public static

Defined in display/LBitmapData.js:125

Available since 1.8.8

data type of the LBitmapData. Canvas object。

LBitmapData.DATA_IMAGE

String public static

Defined in display/LBitmapData.js:116

Available since 1.8.8

data type of the LBitmapData. Image object。

objectIndex

Int public

Inherited from LObject: main/LObject.js:11

Available since 1.6.0

ID of the object

width

Float public

Defined in display/LBitmapData.js:61

Available since 1.0.0

The width of the bitmap image in pixels.

x

Float public

Defined in display/LBitmapData.js:45

Available since 1.0.0

The location x of the bitmap image in pixels.

y

Float public

Defined in display/LBitmapData.js:53

Available since 1.0.0

The location y of the bitmap image in pixels.