1
 Paint mPaint = new Paint();
 mPaint.setStyle(Style.FILL);
 mPaint.setColor(Color.Red);
 canvas.drawRect(mRedPaddleRect, mPaint);

Here, mRedPaddleRect is a Rectangle formed using Rect and instead of setting It a color I want set an Image.

How can this be done?

Any help would be appreciated.

Thank You.

Swapnil Patil
  • 971
  • 2
  • 18
  • 41

2 Answers2

7

That is how I did it, I could not believe it was that easy

       Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.racquet);
       canvas.drawBitmap(bitmap, null, mRedPaddleRect, mPaint);

Hopefully this would help out others too.

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

        Canvas canvas = new Canvas(mutableBitmap);

Put you paint code here

        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);

Try something like this hope this helps

Terril Thomas
  • 1,486
  • 13
  • 32