问题
I'm displaying a bitmap on Inside the ImageView and using the Canvas .
ImageView : it display the whole image not matter how large the image, it compress bitmap within the width/height of Imageview.
Canvas : canvas draw the bitmap but if the bitmap is larger it goes out of screen.
How to same behavior for bitmap on canvas like Imageview display.?
回答1:
To resize a bitmap take a look at drawBitmap method in the canvas, Each overloaded method allows you to specify a size. For example here is the signature of one of the methods
public void drawBitmap (int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)
It allows you specify the width and height .
Or
Use public void drawBitmap (Bitmap bitmap, Matrix matrix, Paint paint) and
use public void setScale (float sx, float sy) to resize
Use this to re-size the image based on your needs
来源:https://stackoverflow.com/questions/12243185/resize-images-in-canvas