Resize Images in Canvas

时光毁灭记忆、已成空白 提交于 2019-12-10 11:40:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!