这里用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();
android下高效率的J2ME API之Graphics.drawRegion
最新推荐文章于 2024-11-04 11:45:54 发布