Reputation: 17
I know how to crop images in android using 3rd party libraries, But I want to split a single picture into multiple pictures as grids for Instagram Feed according to user preference (3x3, 3x1 etc)
Just like: https://play.google.com/store/apps/details?id=com.instagrid.free&hl=en
How to approach this? Is there any particular library?
Upvotes: -2
Views: 366
Reputation: 51
Assuming that you have a function to crop image like this:
public Image crop(Image src, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY);
This example code will help you split you picture into R rows and C columns:
public List<Image> split(Image src, int r, int c) {
List<Image> result = new ArrayList<>();
int topLeftX, topLeftY, bottomRightX, bottomRightY;
int res_height = src.height / r;
int res_width = src.width / c;
for (int i = 0; i < r; i++) {
topLeftX = i * res_height;
bottomRightX = (i + 1) * res_height;
for (int j = 0; j < c; j++) {
topLeftY = j * res_width;
bottomRightY = (j + 1) * res_width;
result.add(crop(src, topLeftX, topLeftY, bottomRightX, bottomRightY));
}
}
return result;
}
Upvotes: 0