2011-12-02 27 views
1

在我的Android繪畫應用程序中,我將在畫布上繪畫。 但有些時候我有圖像之前,油漆。那時我的油漆變慢了。哪裏有問題 ??爲什麼圖像上的顏色變慢?

,只有在畫布上作畫的代碼:

@Override 
    protected void onDraw(Canvas canvas) { 

     //canvas.drawColor(0, PorterDuff.Mode.CLEAR); 
     // set the Canvas Color 
     canvas.drawColor(canvasColor); // edited 

     canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); 

     canvas.drawPath(mPath, mPaint); 

    } 

這讓作爲背景圖像的代碼是:

@Override 
    protected void onDraw(Canvas canvas) { 

     //canvas.drawColor(0, PorterDuff.Mode.CLEAR); 
     // set the Canvas Color 
     canvas.drawColor(canvasColor); // edited 

     if(!(imagePath==null)) 
     { 
      Bitmap tempBitmap = BitmapFactory.decodeFile(imagePath); // from the gallery 
      photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true); 
     } 
     if(!(imagePath==null)) 
     { 
      canvas.drawBitmap (photoBitmap,0, 0, null); 
     } 


     canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); 
    canvas.drawPath(mPath, mPaint); 

    } 

現在,我不知道爲什麼我的油漆慢變,而我的油漆在畫布上,如果有圖像作爲背景。 請幫我。 謝謝。

+1

你也可以使用ImageLoader快速獲取圖像...試試吧... –

+0

@HardikGajjar:謝謝Hardik。 :-) –

+0

@HardikGajjar:我的問題是關於不加載圖像,但我的塗料變得緩慢,而有一個圖像作爲背景。 –

回答

5

由於此行,您的應用程序可能會變慢Bitmap tempBitmap = BitmapFactory.decodeFile(imagePath);您的onDraw函數中的。如果你在每個實例都改變了位圖,那麼你應該在onDraw之外聲明它,只需將它指定給新的位圖,並且如果你沒有改變它,那麼只需在開始時初始化和分配對象,然後在onDraw中將其繪製在畫布上。

+0

感謝您的回覆。讓我試試看。 –

+0

我應該在哪裏解碼文件? –

+0

你可以在繪圖類構造器中做到這一點.. –

相關問題