drawBitmap 不是全屏的
我使用 onDraw 方法显示图像,如下所示:
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.photo0);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(background, 0, 0, null);
我想将此图像设置为背景,但它仅显示在屏幕的一部分上。如何设置为全屏?
有没有办法从 xml 将图像设置为背景并通过 onDraw 方法在此图像上绘制其他图像?
I display an image using onDraw Method like this :
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.photo0);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(background, 0, 0, null);
I want to set this image as background, but it is displayed only on a part of the screen. How to set it as fullscreen?
There is a way to set the image as background from xml and to draw other images on this image from onDraw Method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
这会将位图的一部分(“null”表示整个位图)渲染到 dest 指定的屏幕区域(在本例中是视图的整个区域)。
请注意,这将/可能会改变纵横比,具体取决于背景,您可能需要修复它。
try this:
This renders a part of the bitmap ("null" means the whole bitmap) to the screen area specified by dest (which is the whole area of the view in this case).
Note that this will/might change the aspect ratio, depending on the background, you might need to fix that.
这对我有用。
This is working for me.