0
我想調用一個函數從onDraw()繪製位圖圖像。 其實我需要在onDraw()之外繪製位圖圖像。 幫幫我。 謝謝。在onDraw函數外部繪製位圖圖像Canvas Android
我想調用一個函數從onDraw()繪製位圖圖像。 其實我需要在onDraw()之外繪製位圖圖像。 幫幫我。 謝謝。在onDraw函數外部繪製位圖圖像Canvas Android
您可以通過下面的代碼繪製位圖:
ImageView mImage = (ImageView) findViewById(R.id.iv_coloring_figure);
BitmapDrawable drawable = (BitmapDrawable) mImage.getDrawable();
Bitmap bmp = drawable.getBitmap();
Bitmap bitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(_alteredBitmap);
Paint paint = new Paint();
Matrix matrix = new Matrix();
canvas.drawBitmap(bmp, matrix, paint);
mImage.setImageBitmap(bitmap);
現在用於創建位圖時,根據圖像的來源不同的方法。在這裏,我將圖像設置爲ImageView,並從該圖像創建一個位圖並在畫布上繪製。
編輯: 好吧,從你最後的評論,我才知道你想要什麼。 Here是使用SurfaceView
的一個很好的例子。如果你是遊戲編程的初學者,你可以一步一步地通過這個tutorial。
如果我需要移動畫布中的位圖圖像,那麼我應該如何在這種情況下使用線程? – Paramita
你是什麼意思移動位圖,請多解釋一下。 – 2013-08-31 09:22:43
意思是我想移動位圖中包含的圖像。在任何遊戲中,遊戲主題的背景都會自動移動。我只是想不斷移動背景...... – Paramita