Tom
Tom

Reputation: 296

How to move a drawable image to bottom of canvas in android

In my app i have created a PDF file and i hve used canvas to draw texts and images,My problem is ,I want to add an image on the bottom of the PDF page,So that i have used this code;

 Drawable icon = ContextCompat.getDrawable(context,R.drawable.book);

        icon.setBounds(80, 60, 180, 200);
        icon.draw(canvas2);

Using this code I could draw my app icon on the canvas,How can i move this to bottom of my pdf document, any methods for that??Can anyone help??

Upvotes: 0

Views: 567

Answers (1)

Jack
Jack

Reputation: 1855

int halfWidth = Width/2;
int halfHeight = Height/2
Rect dstRectForRender = new Rect( X - halfWidth, Y - halfHeight, X + halfWidth, Y + halfHeight );
canvas.drawBitmap ( someBitmap, null, dstRectForRender, null );

Upvotes: 1

Related Questions