2012-03-07 70 views
0

這裏需要一點幫助:我走了,現在的想法......帆布畫:不能渲染動畫與運行時生成位圖圖像

這就是我需要做的:

  • 渲染「base」圖像[由ARGB.8888字節數組創建]
  • 用戶在屏幕上單擊2點;我需要對從一個點到另一個點的路徑周圍的像素區域執行像素操作... [我需要計算整個路徑上每個像素的squre塊像素]。
  • 隨着代碼以動畫形式前進,顯示圖像的修改。

我能夠顯示整個路徑;我能夠計算&正確操縱像素..但我無法做的是顯示動畫,因爲我的代碼正在路徑上進行......使用當前實現,我可以在最後顯示整個計算路徑...

public void onDraw(Canvas canvas){ 

canvas.drawColor(Color.WHITE); 
Paint p = new Paint(); 
canvas.drawBitmap(base,0,0,p); 

traverse clickEvent1.x -> clickEvent2.x 
     traverse for clickEvent1.Y -> clickEvent2.Y 
      { 
      newBitMap = calculateNewBitMap(base) 

      // I nee to redraw Canvas with (newBitMap) 
      // canvas.drawBitMap(newBitMap); 

      //Doesn't work 
      //postInvalidate(); 
      //invalidate() 

      //AnimationDrawable.addFrame(newBitMap) 

      // I am not calling start here 
      //but just wanted to let you know that I do call animation start to display the frames stored in it 
      // animation.start(); 
      } 

// obviously wouldn't work here As it is already out of the loop 
//invalidate(); 
} 

請注意:

  1. 的newBitMap圖像是在運行時產生的,它不會提供給我事先...
  2. 我試圖在環無效()作爲好 ;但它只會在整個循環遍歷之後繪製累積結果,而不是newBitMaps的中間狀態。
  3. 性能是至關重要的+我正在處理巨大的圖像大小..所以請記住,以及...如果我創建多個位圖臨時存儲JVM由於「OutofMemory」崩潰..
  4. 我嘗試以「AnimationDrawable」形式存儲新圖像;但THT不是解決問題以及....

    AnimationDrawable animDrawable = new AnimationDrawable(); 
    Drawable frame1 = new BitmapDrawable(newCaclBitMap); 
    animDrawable.addFrame(frame1, 250); 
    

感謝任何指針/建議..

回答

1

看起來你正在做的是在一次調用onDraw()時運行所有的繪圖邏輯,當我認爲你想要的是讓onDraw()爲動畫的每一幀調用一次。

因此,而不是在你的蹤跡是這樣的:

onDraw() 
    drawFrame() 
    drawFrame() 
    drawFrame() 
    ... 

你必須這樣:

onDraw() 
    drawFrame() 
onDraw() 
    drawFrame() 
onDraw() 
    drawFrame() 
... 

CubeLiveWallpaper example有這種類型的事情的一個例子。

+0

感謝您將我指向CubeLiveWallpaper ...我解決了「LunarLander」和「cubeLiveWallpaper」實現方面的問題 – Pranav 2012-03-09 19:55:05

0

Animation對象用於動畫View對象。你想要做的是動畫畫布。這更復雜但可能更強大。基本上你需要推導出一個方程來控制你作爲時間函數繪製的運動。當動畫開始時,您將獲得當前的時間戳,然後使用onDraw方法繪製畫布在該時間點應該看起來像的樣子。基本上你必須畫出每一步。