在调整图像画布画布、图像

2023-09-06 15:39:30 作者:′ 努力奋斗 。

我在里面ImageView的显示位图和使用Canvas。

I'm displaying a bitmap on Inside the ImageView and using the Canvas .

ImageView的:它显示整个图像没有多么大的图像,它融为一体preSS的ImageView的宽度/高度内的位图

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.

如何同为像ImageView的显示帆布位图的行为?

How to same behavior for bitmap on canvas like Imageview display.?

推荐答案

要调整位图看看 drawBitmap 在画布方法,每个重载方法允许你指定一个尺寸。例如,下面是其中的一种方法的签名

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

公共无效drawBitmap(INT []的色彩,诠释抵消,诠释步幅,诠释的x,INT Y,INT宽度,INT的高度,布尔hasAlpha,油漆涂料)

它允许您指定的宽度和高度。

It allows you specify the width and height .

或者

使用 公共无效drawBitmap(位图的位图,矩阵的矩阵,涂料粉刷) 以及

使用 公共无效setScale(浮点SX,SY浮动) 来调整

使用此重新大小根据你的需要的图片

Use this to re-size the image based on your needs