LBitmapData Class
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
Parameters:
-
image
ImageThe Image object。
-
x
FloatThe x coordinate of the image.(Optional).
-
y
FloatThe y coordinate of the image.(Optional).
-
width
FloatThe width of the bitmap image in pixels.(Optional).
-
height
FloatThe height of the bitmap image in pixels.(Optional).
-
dataType
StringYou 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);
}
Item Index
Methods
Properties
- dataType
- height
- LBitmapData.DATA_CANVAS static
- LBitmapData.DATA_IMAGE static
- objectIndex
- width
- x
- y
Methods
callParent
-
functionName
-
arguments
call the method of parent。
Parameters:
-
functionName
Stringfunction's name
-
arguments
ArrayFixed 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
Returns a new BitmapData object that is a clone of the original instance with an exact copy of the contained bitmap.
Returns:
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
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
LRectangleA LRectangle object that defines the area of the image in which the LColorTransform object is applied.
-
colorTransform
LColorTransformA 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
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
LBitmapDataThe 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
LRectangleA rectangle that defines the area of the source image to use as input.
-
destPoint
LPointThe 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
Draws the source display object onto the bitmap image, using the Flash runtime vector renderer.
Parameters:
-
[source]
LDisplayObject | LBitmapData optionalThe display object or LBitmapData object to draw to the LBitmapData object.
-
matrix
LMatrixA 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
LColorTransformA 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.
-
blendMode
StringA string value, from the flash.display.BlendMode class, specifying the blend mode to be applied to the resulting bitmap.
-
clipRect
LRectangleA 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.
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
Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y).
Parameters:
-
x
IntThe x position of the pixel.
-
y
IntThe y position of the pixel.
-
colorType
Stringthe color type. [number|array].(Optional).
Returns:
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
Generates an array from a rectangular region of pixel data.
Parameters:
-
rect
LRectangleA rectangular area in the current BitmapData object.
Returns:
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
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
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
LRectangleSpecifies the rectangular region of the BitmapData object.
-
data
Arraythe 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
Change coordinate of the Image's visual range
Parameters:
-
x
FloatThe x coordinate of the image.
-
y
FloatThe 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
Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y).
Parameters:
-
x
IntThe x position of the pixel whose value changes.
-
y
IntThe y position of the pixel whose value changes.
-
data
ArrayThe resulting pixel data for the pixel.
Returns:
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
Sets rect pixels of a LBitmapData object.
Parameters:
-
rect
LRectangleSpecifies the rectangular region of the BitmapData object.
-
data
Arraythe 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
Change the Image's visual range
Parameters:
-
x
FloatThe x coordinate of the image.
-
y
FloatThe y coordinate of the image.
-
width
FloatThe width of the bitmap image in pixels.
-
height
FloatThe 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
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
data type, LBitmapData.DATA_IMAGE(Image object)or LBitmapData.DATA_CANVAS(Canvas object)。
height
Float
public
The height of the bitmap image in pixels.
LBitmapData.DATA_CANVAS
String
public
static
data type of the LBitmapData. Canvas object。
LBitmapData.DATA_IMAGE
String
public
static
data type of the LBitmapData. Image object。
objectIndex
Int
public
ID of the object
width
Float
public
The width of the bitmap image in pixels.
x
Float
public
The location x of the bitmap image in pixels.
y
Float
public
The location y of the bitmap image in pixels.