Android里面没有drawRegion只好重写,
不废话,上代码:
public static void drawRegion(Canvas g,Bitmap bitmap, int x_src, int y_src, int width, int height, int transform, int x_dest, int y_dest,int anchor){ Matrix matrix = new Matrix(); Matrix mirror = new Matrix(); Bitmap img = null; Rect src = new Rect(); src.left = x_src; src.right = x_src + width; src.top = y_src; src.bottom = y_src + height; float mirrorArray[] = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; mirror.setValues(mirrorArray); switch (transform) { case TRANS_NONE: { break; } case TRANS_ROT90: { matrix.preRotate(90); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } case TRANS_ROT180: { matrix.preRotate(180); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } case TRANS_ROT270: { matrix.preRotate(270); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } case TRANS_MIRROR: { // TODO matrix.postConcat(mirror); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } case TRANS_MIRROR_ROT90: { // TODO matrix.postConcat(mirror); matrix.preRotate(90); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } case TRANS_MIRROR_ROT180: { // TODO matrix.postConcat(mirror); matrix.preRotate(180); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } case TRANS_MIRROR_ROT270: { // TODO matrix.postConcat(mirror); matrix.preRotate(270); img = Bitmap.createBitmap(bitmap, src.left, src.top, src.right, src.bottom, matrix, true); break; } } g.drawBitmap(img, x_dest, y_dest, null); }
这里主要是利用了Matrix来处理。
drawBitmap里面有对矩阵的支持。
小tips:在Matrix相关类里分别有Preconcats matrix与Postconcats matrix
Preconcats matrix相当于右乘矩阵,Postconcats matrix相 当于左乘矩阵。
刚才google翻译竟然木有,唉,专业用语。
另外,今儿又折腾了半天原来依稀记着碰到过,后来却怎么也折腾不好的问题。
问题是这样儿的,我继承了SurfaceView类,却死活不调draw
后来发现
在Activity里的OnCreate里 super.onCreate(savedInstanceState); //setContentView(R.layout.main);//就是这句没注掉,基础啊,基础,唉,回去仔细研究Android结构去!!! cGame game = new cGame(this); setContentView(game); 注释部分出了问题,唉,基础啊基础,好长时间不用又忘了!!!
再次记录,去掉这一行,换成View类,好啦,SurfaceView不成的主要问题,估计是runnable哪儿还没添加调用,书在斩哥哪儿,等拿回来了再试一下。