一般来说,一个JPG或PNG图象可能包括有几个部份(比如小狗跑步的起步,第一步,第二步)组成,
要分割出来,可以用Bitmap来做。
Bitmap p = BitmapFactory.decodeResource(context.getResources(), R.drawable.dog);
Log.d("Bitmap p", "" + p.getWidth() + " " + p.getHeight());
Bitmap p1 = Bitmap.createBitmap(p, 0, 0, 35, 26);
new BitmapDrawable(p1);
// 从p这个图中的点左上角(0,26)到点右下角(35,0)中的矩形图象
Rect (int left, int top, int right, int bottom)
the caller must ensure that left <= right and top <= bottom
left The X coordinate of the left side of the rectagle
top The Y coordinate of the top of the rectangle
right The X coordinate of the right side of the rectagle
bottom The Y coordinate of the bottom of the rectangle
即是左上角为坐标原点,左上角(left,top)的点与右下角(right,bottom)的点
Bitmap.createBitmap(p, left, top, width, height);
这个的width,height和上面的Rect的right,bottom参数是不同的,
android游戏个人经验4[转]
最新推荐文章于 2024-07-12 13:31:47 发布
posted by David Chen at May 06, 2009 12:25 AM