2017-09-11 88 views
0

請幫我解釋我在做什麼錯誤。我必須使用基於應用程序邏輯的不同顏色在圖像後面繪製一個圓圈(以位圖形式給出),我使用以下代碼。畫布在現有圖像後面繪製圓形

 Bitmap workingBitmap = Bitmap.createBitmap(bitmap); 
     Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true); 

     Canvas canvas = new Canvas(mutableBitmap); 

     Paint paint = new Paint(); 
     paint.setAntiAlias(true); 
     paint.setColor(Color.BLUE); 
     paint.setStyle(Paint.Style.FILL_AND_STROKE); 

     int horizontalPadding = (iconSize - drawingWidth)/2; 
     int verticalPadding = (iconSize - drawingHeight)/2; 

     canvas.drawCircle(120, 120, 100, paint); 
     return mutableBitmap; 

什麼,我得到的是形象,這只是完全覆蓋圖像,如何告訴圖像具有上層上面的代碼了一圈。

謝謝

回答

1

在您的代碼中,您使用mutableBitmap作爲畫布並在其上畫圓。如果您想在圓圈上方繪製圖像,應在繪製圓圈後繪製它。代碼:

Bitmap workingBitmap = Bitmap.createBitmap(bitmap); 
    Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true); 
    // Create an empty bitmap 
    Bitmap output = Bitmap.createBitmap(mutableBitmap.getWidth(), mutableBitmap.getHeight(), 
      mutableBitmap.getConfig()); 
    // Use empty bitmap as canvas 
    Canvas canvas = new Canvas(output); 

    Paint paint = new Paint(); 
    paint.setAntiAlias(true); 
    paint.setColor(Color.BLUE); 
    paint.setStyle(Paint.Style.FILL_AND_STROKE); 

    int horizontalPadding = (iconSize - drawingWidth)/2; 
    int verticalPadding = (iconSize - drawingHeight)/2; 

    canvas.drawCircle(120, 120, 100, paint); 
    // And now draw image above circle 
    canvas.drawBitmap(mutableBitmap, 0, 0, null); 
    return output; 
+0

謝謝你的工作 –