2012-12-12 78 views
0

我正在創建一個簡單的繪圖原型,用於Android用戶可以拖動他的手指穿過屏幕和繪製基本的線條/形狀等我有一些性能問題在同一領域進行繪製時,在一段時間後性能下降很大。繪圖多次與圖形和存儲到相同的位圖

我想知道是否有任何方式,在繪製線之後(觸摸開始後,觸摸移動並觸摸結束事件鏈),將新繪製的線存儲到包含其餘部分的位圖中圖紙。

我看過bitmap.merge(),但是這會在混合顏色時產生問題。我只是希望任何新的「繪圖」能夠保存在先前繪製的所有內容之上。

// To hold current 'drawing' 
var clip:Shape = new Shape(); 

// To hold past 'drawings' 
var drawing:Bitmap = new Bitmap(); 

public function Main() 
{ 
    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; 

    addChild(drawing); 
    addChild (clip); 

    addEventListener(TouchEvent.TOUCH_BEGIN, tBegin); 
    addEventListener(TouchEvent.TOUCH_MOVE, tMove); 
    addEventListener(TouchEvent.TOUCH_END, tEnd); 
} 

private function tBegin(e:TouchEvent):void 
{ 
    clip.graphics.lineStyle(28,0x000000); 
    clip.graphics.moveTo(mouseX, mouseY); 
} 

private function tMove(e:TouchEvent):void 
{ 
    clip.graphics.lineTo(mouseX, mouseY); 
} 

private function tEnd(e:TouchEvent):void 
{ 
    // Save new graphics and merge with drawing 
} 

回答

2

剛在你的夾子形狀繪製,並傾向於借鑑分配到一個位圖

// To hold current 'drawing' 
var bmpData:BitmapData = new BitmapData (800, 800) // put here your desired size 

var clip:Shape = new Shape(); 

// To hold past 'drawings' 
var drawing:Bitmap = new Bitmap(bmpData); 

public function Main() 
{ 
    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; 

    addChild(drawing); 
    addChild (clip); 



    addEventListener(TouchEvent.TOUCH_BEGIN, tBegin); 
    addEventListener(TouchEvent.TOUCH_MOVE, tMove); 
    addEventListener(TouchEvent.TOUCH_END, tEnd); 
} 

private function tBegin(e:TouchEvent):void 
{ 
    clip.graphics.lineStyle(28,0x000000); 
    clip.graphics.moveTo(mouseX, mouseY); 
} 

private function tMove(e:TouchEvent):void 
{ 
    clip.graphics.lineTo(mouseX, mouseY); 
} 

private function tEnd(e:TouchEvent):void 
{ 
    // Save new graphics and merge with drawing 
    bmpData.draw (clip); 
    clip.graphics.clear(); 
} 
一個位圖數據夾內