I have images on my android app. How cut this picture into 9 or 12 equal parts and add these parts an array?
Asked
Active
Viewed 3,595 times
2
-
The parts may not overlap? What do you mean by *equal parts*? You mean in terms of size? – aioobe Sep 29 '11 at 10:35
-
http://stackoverflow.com/questions/4754985/android-split-drawable/4755479#4755479 – ingsaurabh Sep 29 '11 at 10:39
-
yes, 9 parts the same size. For example the original image has a size 600x600, all parts has size 200x200. – Gene Sep 29 '11 at 10:49
1 Answers
6
This will work:
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;

Zain
- 37,492
- 7
- 60
- 84

mayank_droid
- 1,015
- 10
- 19