使用方法 -canvas.drawBitmap(bitmap, src, dst,paint) [英] Using method -canvas.drawBitmap(bitmap, src, dst, paint)

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

问题描述

每次我使用这段代码时,什么都没有绘制.我需要在指定的矩形内绘制位图.

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.

推荐答案

EDIT

原来的答案是错误的.您可以使用 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.

根据他在某物下方绘制的油炸锅评论,我会在此添加注释.

As per the fryer comment he was drawing beneath something, I'll add a note on that.

drawBitmap(bitmap, srcRect, destRect, Paint)不处理 Z ordering (depth) 和在对象上调用 draw 的顺序很重要.

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 specified any source, so its not drawn anything.

示例:

您有一个 100x100 像素的位图.您想绘制整个位图.

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);

您需要指定源矩形,源矩形可以是从 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(bitmap, src, dst,paint)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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