2012-05-04 16 views
0

我試圖在柔性繪製位圖,原始位圖是如何使用beginBitmapFill?

enter image description here

但實際上它顯示在應用程序看起來像

enter image description here

這裏是代碼:

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

如果你想在原點外畫東西,你需要在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(); 
+0

我剛剛自己解決了這個問題,但你是對的!這是正確的答案。 – wtm

+0

糟糕。我從來沒有注意到你已經知道了。那麼,我猜想只是一個參考。 – montzkie

2

我認爲「leakBitmapData」是由代碼生成或加載在應用程序中的位圖數據。

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); 
+0

我已經解決了這個問題,我需要做一個矩陣變換。但是,謝謝你們都一樣。 – wtm