0

我正在尝试在 flex 中绘制位图,原始位图是

在此处输入图像描述

但是,实际上它显示在应用程序中看起来像

在此处输入图像描述

这是代码:

this.component.graphics.beginBitmapFill(leakBitmapData);
this.component.graphics.drawRect(leakPoint.x-halfWidth,leakPoint.y-halfHeight,leakBitmapData.width,leakBitmapData.height);
this.component.graphics.endFill();

只有当我在 (0,0) 处绘制矩形时,它看起来是正确的。为什么?

4

2 回答 2

4

如果要在原点之外绘制一些东西,则需要对 BitmapData 进行矩阵转换。像这样的东西:

var px:int = leakPoint.x - halfWidth;
var py:int = leakPoint.y - halfHeight;
var translationMatrix:Matrix = new Matrix;
translationMatrix.tx = px;
translationMatrix.ty = py;

this.component.graphics.beginBitmapFill(leakBitmapData, translationMatrix);
this.component.graphics.drawRect(px, py, leakBitmapData.width, leakBitmapData.height);
this.component.graphics.endFill();
于 2012-05-04T08:30:38.650 回答
2

I assumed that "leakBitmapData" is a bitmapdata which is generated by code or loaded in the application.

this.component.graphics.beginBitmapFill(leakBitmapData, null, true, false);
this.component.graphics.drawRect(0,0, leakBitmapData.width, leakBitmapData.height);
this.component.graphics.endFill();

this.component.x = -(leakBitmapData.width/2);
this.component.y = -(leakBitmapData.height/2);
于 2012-05-04T07:03:05.773 回答