开发者

How to cut the picture into equal parts?

开发者 https://www.devze.com 2023-04-09 01:36 出处:网络
I have images on my android app. How cut this pictu开发者_Go百科re into 9 or 12 equal parts and add these parts an array?This will work:

I have images on my android app. How cut this pictu开发者_Go百科re into 9 or 12 equal parts and add these parts an array?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号