【问题标题】:Use an image as the background of a canvas and keep it resized使用图像作为画布的背景并保持调整大小
【发布时间】:2018-03-11 10:48:06
【问题描述】:

我目前正在开发一款 Android 应用。我有一个画布,用户可以在上面画一些东西。我需要一张图片作为这个画布的背景。

我已经设法导入一张图片并将其设置为背景使用

mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_background_pic));

但是,图片看起来比屏幕大十倍。

是否可以调整图片大小,使其充满画布而不是更多?


另外,稍后我需要在活动中添加其他内容。画布不会是屏幕上唯一的东西,所以我需要图片是画布的大小,而不是屏幕。

非常感谢。

【问题讨论】:

标签: android canvas view resources scale


【解决方案1】:

没关系,我找到了它:

canvas.drawBitmap(bitmap, null, new RectF(0, 0, canvasWidth, canvasHeight), null);

由 Kai at stackoverflow.com/a/27466127/8205282

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 2014-01-07
    • 2013-05-29
    • 2017-08-24
    • 2011-10-14
    • 2020-08-09
    • 1970-01-01
    • 2011-09-10
    相关资源
    最近更新 更多