2016-10-08 4 views
0

Ich habe canvas.drawbitmap(bitmap,matrix,paint) verwendet, um die Bitmap auf Leinwand zu zeichnen. Ja, es hat die meiste Zeit funktioniert! Aber manchmal hat es nicht funktioniert. Es gab nichts auf der Leinwand, nachdem ich die Methode aufgerufen hatte canvas.drawbitmap(); Also, was ist los?canvas.drawbitmap funktioniert manchmal nicht

1: wählte ich ein Bild aus dem Album und bekam die Bitmap, die bgBitmap

2 genannt: Erstellt ein CanvasView die View erstreckt. Dann Erstellen Sie eine leere Bitmap auf der Leinwand, um etwas darauf zu malen.

mBitmap = Bitmap.createBitmap(screenWidth, screenHeight,Bitmap.Config.RGB_565); 
mCanvas = new Canvas(mBitmap); 
mCanvas.drawColor(Color.WHITE); 

protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    canvas.drawColor(getResources().getColor(R.color.color_white)); 
    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); 
} 

3: Zeichnen Sie das Bild auf der Leinwand.

Es funktionierte die meiste Zeit, aber manchmal hat es nicht funktioniert.

+0

zeigen Sie Ihre Codes an – Thinsky

Antwort

0

1: Ich wählte ein Bild aus dem Album und bekam die Bitmap mit dem Namen bgBitmap;

2: Erstellt eine CanvasView, die View.Then erweitert, Erstellen Sie eine leere Bitmap auf Leinwand, um etwas darauf zu malen.

mBitmap = Bitmap.createBitmap(screenWidth, screenHeight,Bitmap.Config.RGB_565); 
mCanvas = new Canvas(mBitmap); 
mCanvas.drawColor(Color.WHITE); 

protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    canvas.drawColor(getResources().getColor(R.color.color_white)); 
    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); 
} 

3: das Bild auf der Leinwand ziehen.

es funktionierte die meiste Zeit, aber manchmal hat es nicht funktioniert.

Verwandte Themen