如何在Android中创建类似于Instagram的网格视图?

问题描述 投票:-1回答:1

[我知道如何使用第三方库在android中裁剪图像,但是我想根据用户的偏好(3x3、3x1等)将一张图片分成多张图片作为Instagram Feed的网格]

就像:https://play.google.com/store/apps/details?id=com.instagrid.free&hl=en

如何处理?有没有特别的图书馆?

android gridview imageview cropper
1个回答
0
投票

假设您具有像这样裁剪图像的功能:

public Image crop(Image src, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY);

此示例代码将帮助您将图片分成R行和C列:

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.