我使用画布并且图像为1000x500,手机宽度为480,高度为800
比例样本:
scale = (float) (height / image.getHeight());
image_width = image.getWidth() * scale;
image_height = image.getHeight() * scale;
如何使用画布绘制此缩放图像,只有左侧和右侧位于屏幕外时图像的中心(屏幕尺寸)可见?
答案 0 :(得分:2)
这样做
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);
您还可以缩放和翻译(移动)整个画布
canvas.scale(float scaleX, float scaleY);
canvas.translate(float dx, float dy);