使用方法-canvas.drawBitmap(位图,SRC,DST,油漆) [英] Using method -canvas.drawBitmap(bitmap, src, dst, paint)

查看:511
本文介绍了使用方法-canvas.drawBitmap(位图,SRC,DST,油漆)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我用这个code什么也不绘制。我需要绘制一个位图指定的矩形内。

Everytime I use this code nothing is drawn. I need to draw a bitmap inside of a specified rectangle.

canvas.drawBitmap(MyBitmap, null, rectangle, null)

我已经看了网上却找不到多少帮助。

I've looked online but can't find much help.

推荐答案

修改

原来答案是不正确。 您可以使用与sourceRect指定一个位图绘制的一部分。 它可以是空,在这种情况下,整个图像将被使用。

The original answer is incorrect. You can use the sourceRect to specify a part of a Bitmap to draw. It may be null, in which case the whole image will be used.

由于从他在画什么下方的提问者的意见,我会添加注释上。

Given the comment from the asker that he was drawing beneath something, I'll add a note on that.

drawBitmap(位图,srcRect,destRect,油漆)不处理ž排序(深度),并呼吁借鉴对象问题的顺序。

drawBitmap(bitmap, srcRect, destRect, paint) does not handle Z ordering (depth) and the order of calling draw on object matters.

如果您有3个形状绘制,方形,三角形和圆形。如果你想在广场在上面,那么它必须在最后绘制。

If you have 3 shapes to be drawn, square, triangle and circle. If you want the square to be on top then it must be drawn last.

你没有指定源,所以它不是画什么。

You're not specifying a source, so its not drawing anything.

例如:

您有一个位图100×100像素。要绘制整个位图。

You have a Bitmap 100x100 pixels. You want to draw the whole Bitmap.

canvas.drawBitmap(MyBitmap, new Rect(0,0,100,100), rectangle, null);

您要绘制位图的只有左半部分。

You want to draw only the left half of the bitmap.

canvas.drawBitmap(MyBitmap, new Rect(0,0,50,100), rectangle, null);

您需要指定源rect,源rect可以从0,0任何地方是一个长方形的宽度,位图的高度。

You need to specify the source rect, the source rect can be a rectangle anywhere from 0,0 to the width,height of the bitmap.

这篇关于使用方法-canvas.drawBitmap(位图,SRC,DST,油漆)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆