android下高效率的J2ME API之Graphics.drawRegion

这里用android API封装了个drawRegion,效率还是蛮高,并不需要使用创建临时对象,这里贴出主要代码 canvas 源自于android.graphics.Canvas public void drawRegion(Image img, int x_src, int y_src, int width, int height, int transform, int x_dest, int y_dest, int anchor) { canvas.save(); setAnchor(anchor); int ix = 0, iy = 0; switch (transform) { case Sprite.TRANS_NONE: // 0 break; case Sprite.TRANS_ROT90: // 90 canvas.rotate(90, x_dest, y_dest); iy = height; break; case Sprite.TRANS_ROT180: // 180 canvas.rotate(180, x_dest, y_dest); iy = height; ix = width; break; case Sprite.TRANS_ROT270: // 270 canvas.rotate(270, x_dest, y_dest); ix = width; break; case Sprite.TRANS_MIRROR: // M canvas.scale(-1, 1, x_dest, y_dest);// 镜像 ix = width; break; case Sprite.TRANS_MIRROR_ROT90: // M90 j2me<-->android 270 canvas.scale(-1, 1, x_dest, y_dest);// 镜像 canvas.rotate(270, x_dest, y_dest); ix = width; iy = height; break; case Sprite.TRANS_MIRROR_ROT180: // M180 canvas.scale(-1, 1, x_dest, y_dest);// 镜像 canvas.rotate(180, x_dest, y_dest); iy = height; break; case Sprite.TRANS_MIRROR_ROT270: // M270 j2me<-->android 90 canvas.scale(-1, 1, x_dest, y_dest);// 镜像90 canvas.rotate(90, x_dest, y_dest); break; } canvas.clipRect(x_dest - ix, y_dest - iy, x_dest - ix + width, y_dest - iy + height); canvas.drawBitmap(img.mImage, x_dest - ix - x_src, y_dest - iy - y_src, paint); canvas.restore();
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值