Paint mPaint = new Paint();
mPaint.setStyle(Style.FILL);
mPaint.setColor(Color.Red);
canvas.drawRect(mRedPaddleRect, mPaint);
在這裏,mRedPaddleRect是使用Rect形成的矩形,而不是將其設置爲我想設置圖像的顏色。是否可以設置圖像來繪製對象而不是顏色?
這怎麼辦?
任何幫助,將不勝感激。
謝謝。
Paint mPaint = new Paint();
mPaint.setStyle(Style.FILL);
mPaint.setColor(Color.Red);
canvas.drawRect(mRedPaddleRect, mPaint);
在這裏,mRedPaddleRect是使用Rect形成的矩形,而不是將其設置爲我想設置圖像的顏色。是否可以設置圖像來繪製對象而不是顏色?
這怎麼辦?
任何幫助,將不勝感激。
謝謝。
Bitmap workingBitmap = Bitmap.createBitmap(result);
Bitmap mutableBitmap = workingBitmap
.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
把你畫在這裏
Paint paint = new Paint();
paint.setColor(context.getResources().getColor(R.color.text_color)); // Text
paint.setStrokeWidth(12); // Text Size
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text
// Overlapping
// Pattern
// some more settings...
canvas.drawBitmap(mutableBitmap, RECTsrc, RECTdst, paint);
代碼嘗試這樣的事情,希望這有助於
好的,謝謝!將嘗試這一點,但我應該在哪裏設置圖像的路徑,即要顯示的圖像(正在存儲在資源的Drawable中)? –
試試這個鏈接:http://stackoverflow.com/a/5176495/1562755 –
我希望答案有幫助 –
這是我做到了,我簡直不敢相信它是那麼容易
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.racquet);
canvas.drawBitmap(bitmap, null, mRedPaddleRect, mPaint);
希望這會幫助其他人。
您可以使用位圖。 –
你是否想要將圖像添加到畫布上? –
不是整個畫布,而是我創建的Rect對象。 –