Reputation: 569
I'm using canvas and have an image 1000x500, phone width 480 and height 800
Scale sample:
scale = (float) (height / image.getHeight());
image_width = image.getWidth() * scale;
image_height = image.getHeight() * scale;
How do I draw this scaled image using canvas, having only center(screen size) of the image visible while left and right sides are outside of screen?
Upvotes: 0
Views: 904
Reputation: 1568
do it this way
Rect rs = new Rect();
Rect rd = new Rect();
rs.left = rs.top = 0;
rs.right = 480;
rs.bottom = 800;
<calculate destination rectangle from device size>
canvas.drawBitmap(myBitmap, rs, rd, null);
You can also scale and translate (shift) the entire canvas
canvas.scale(float scaleX, float scaleY);
canvas.translate(float dx, float dy);
Upvotes: 2