Ashish Vishwakarma
Ashish Vishwakarma

Reputation: 131

Is it possible to Set Image to paint object instead of color?

 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.

Upvotes: 1

Views: 9253

Answers (2)

Ashish Vishwakarma
Ashish Vishwakarma

Reputation: 131

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.

Upvotes: 7

Terril Thomas
Terril Thomas

Reputation: 1506

    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

Upvotes: 2

Related Questions