利用 Android 的 Matrix 类实现 J2ME 的 drawRegion 的镜像方法
2010-04-09 06:16:00 来源:WEB开发网Matrix temp2 = new Matrix();
float[] mirrorY = {
-1, 0, 0,
0, 1, 0,
0, 0, 1
};
temp.setValues(mirrorY);
switch(transform){
case Sprite.TRANS_NONE:
break;
case Sprite.TRANS_ROT90:
mMatrix.setRotate(90,width/2, height/2);
break;
case Sprite.TRANS_ROT180:
mMatrix.setRotate(180,width/2, height/2);
break;
case Sprite.TRANS_ROT270:
mMatrix.setRotate(270,width/2, height/2);
break;
case Sprite.TRANS_MIRROR:
mMatrix.postConcat(temp);
break;
case Sprite.TRANS_MIRROR_ROT90:
mMatrix.postConcat(temp);
mMatrix.setRotate(90,width/2, height/2);
break;
case Sprite.TRANS_MIRROR_ROT180:
mMatrix.postConcat(temp);
mMatrix.setRotate(180,width/2, height/2);
break;
case Sprite.TRANS_MIRROR_ROT270:
mMatrix.postConcat(temp);
mMatrix.setRotate(270,width/2, height/2);
break;
}
mMatrix.setTranslate(x_dest, y_dest);
canvas.drawBitmap(newMap, mMatrix, mPaint);
}
public void drawRegion(Image image_src,
int x_src, int y_src,
int width, int height,
int transform,
int x_dest, int y_dest,
int anchor){
if((anchor&VCENTER) != 0){
y_dest -= height/2;
}else if((anchor&BOTTOM) != 0){
y_dest -= height;
}
if((anchor&RIGHT) != 0){
x_dest -= width;
}else if((anchor&HCENTER) != 0){
x_dest -= width/2;
}
Bitmap newMap = Bitmap.createBitmap(image_src.getBitmap(), x_src, y_src, width, height);
Matrix mMatrix = new Matrix();
Matrix temp = new Matrix();
更多精彩
赞助商链接