2
我在我的android应用程序上有图像。如何将此图片分割成9或12个相等的部分并将这些部分添加到数组中?如何将图片剪成相等的部分?
我在我的android应用程序上有图像。如何将此图片分割成9或12个相等的部分并将这些部分添加到数组中?如何将图片剪成相等的部分?
这将工作:
ArrayList<Bitmap> bs= new ArrayList<Bitmap>();
Bitmap b= BitmapFactory.decodeResource(getResources(),R.drawable.photo1);
divideImages(b);
private void divideImages(Bitmap b) {
// TODO Auto-generated method stub
final int width = b.getWidth();
final int height =b.getHeight();
final int pixelByCol = width/2;
final int pixelByRow = height/2;
//List<Bitmap> bs = new ArrayList<Bitmap>();
for(int i=0;i<2;i++){
System.out.println("row no. "+i);
for(int j=0;j<2;j++){
System.out.println("Column no."+j);
int startx=pixelByCol*j;
int starty=pixelByRow*i;
Bitmap b1=Bitmap.createBitmap(b,startx,starty,pixelByCol,pixelByRow);
bs.add(b1);
b1=null;
}
}
b=null;
}
的部分可能不重叠?你的意思是什么*相等的部分*?你的意思是大小? – aioobe
http://stackoverflow.com/questions/4754985/android-split-drawable/4755479#4755479 – ingsaurabh
是的,9部分大小相同。例如,原始图像的尺寸为600x600,所有部件的尺寸均为200x200。 – Gene