android canvas.drawbitmap 参数,android Canvas中的clipRect、drawBitmap

在游戏的开发过程中必定会涉及到N多图片的处理,比如图片的切割、转动、平移等操作,本篇主要描述使用Canvas对图片的clip动作。

Canvas.clipRect(float left, float top, float right, float bottom, Paint paint)这个方法我们自然很明白了,在手机屏幕上裁剪出一块区域来,起点是从屏幕的左上角开始。

当我在用到 Canvas.drawBitmap(Bitmap btmap, float left, float top, Paint paint)方法时,对其中的left、top参数的含义不是很了解,API文档里对这两个参数的描述如下:

left The position of the left side of the bitmap being drawn

top The position of the top side of the bitmap being drawn

翻译过来就是被绘制的图片的左边的位置,被绘制的图片的上边的位置.

当单独使用Canvas.drawBitmap方法的,效果如下(代码中的蓝色矩形是为了突出说明效果,蓝色矩形的大小正好与 jerry照片的大小一致):

操作代码:canvas.save();

mPaint.setColor(Color.BLUE);

canvas.drawRect(0, 0, mBmp.getWidth(), mBmp.getHeight(), mPaint);

canvas.restore();

canvas.save();

canvas.drawBitmap(mBmp, mBmp.getWidth(), mBmp.getHeight(), mPaint);

canvas.restore();

效果图如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值