Divide Image into parts

后端 未结 3 640
后悔当初
后悔当初 2020-12-28 11:04

I have images stored into sd card. I want to divide the image into sixteen equal parts. How to do it using bitmap?

3条回答
  •  别那么骄傲
    2020-12-28 11:27

    Give it a try to somthing like this:

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    
    final int width = dm.widthPixels;
    final int height = dm.heightPixels;
    
    final int pixelByCol = width / 4;
    final int pixelByRow = height / 4; 
    
    List bs = new ArrayList();
    
    Bitmap image = 
    
    for (int i = 0; i < 4) {
        for (int j = 0; j < 4) {
            int startX = pixelByCol * i;
            int startY = pixelByRow * j;
            Bitmap b = Bitmap.createBitmap(image, startX, startY, pixelByCol, pixelByRow);
            bs.add(b);
        }
    }
    

    bs <- your bitmaps

提交回复
热议问题