我使用的帆布画的Android缩放位图的一部分,有一个形象的1000x500,电话宽480,高800用帆布
垢样:
scale = (float) (height/image.getHeight());
image_width = image.getWidth() * scale;
image_height = image.getHeight() * scale;
如何得出这个缩放图像使用画布时,只有图像的中心(屏幕大小)可见,而左侧和右侧在屏幕外?
我使用的帆布画的Android缩放位图的一部分,有一个形象的1000x500,电话宽480,高800用帆布
垢样:
scale = (float) (height/image.getHeight());
image_width = image.getWidth() * scale;
image_height = image.getHeight() * scale;
如何得出这个缩放图像使用画布时,只有图像的中心(屏幕大小)可见,而左侧和右侧在屏幕外?
做这种方式
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);
我建议你看一看[显示位图高效(HTTP:// developer.android.com/training/displaying-bitmaps/index.html) - 你可能不想浪费内存,它可能有助于回答你的问题。 – curtisLoew