Android 如何将位图划分为位图部分

Android 如何将位图划分为位图部分,android,bitmap,Android,Bitmap,你好,我是科姆尼。 我需要一些关于将位图分割成小块的可能方法的信息。 更重要的是,我需要一些选择来判断。我检查了很多帖子,但我仍然不完全相信该怎么做 这两个链接是我找到的一些不错的选择,但我无法计算每种方法的CPU和RAM成本,或者我根本不应该为这个计算而烦恼。尽管如此,如果我要做某事,为什么不从一开始就用最好的方式去做呢 如果能得到一些关于位图压缩的提示和链接,我将不胜感激,这样也许结合这两种方法我会获得更好的性能 我提前向您表示感谢。您想将位图分成若干部分。我假设您要从位图中剪切相等的部

你好,我是科姆尼。 我需要一些关于将位图分割成小块的可能方法的信息。 更重要的是,我需要一些选择来判断。我检查了很多帖子,但我仍然不完全相信该怎么做

这两个链接是我找到的一些不错的选择,但我无法计算每种方法的CPU和RAM成本,或者我根本不应该为这个计算而烦恼。尽管如此,如果我要做某事,为什么不从一开始就用最好的方式去做呢

如果能得到一些关于位图压缩的提示和链接,我将不胜感激,这样也许结合这两种方法我会获得更好的性能


我提前向您表示感谢。

您想将位图分成若干部分。我假设您要从位图中剪切相等的部分。例如,您需要从位图中剪切4个相等的部分

这是一种将位图分成4等份并将其放入位图数组中的方法

public Bitmap[] splitBitmap(Bitmap picture)
{

Bitmap[] imgs = new Bitmap[4];
 imgs[0] = Bitmap.createBitmap(picture, 0, 0, picture.getWidth()/2 , picture.getHeight()/2);
 imgs[1] = Bitmap.createBitmap(picture, picture.getWidth()/2, 0, picture.getWidth()/2, picture.getHeight()/2);
 imgs[2] = Bitmap.createBitmap(picture,0, picture.getHeight()/2, picture.getWidth()/2,picture.getHeight()/2);
 imgs[3] = Bitmap.createBitmap(picture, picture.getWidth()/2, picture.getHeight()/2, picture.getWidth()/2, picture.getHeight()/2);

return imgs;


}

此函数允许您将位图拆分为行数和列数

示例位图[][]位图=拆分位图(bmp,2,1); 将创建存储在二维数组中的垂直分割位图。 2列1行

示例位图[][]位图=拆分位图(bmp,2,2); 将位图拆分为存储在二维数组中的四个位图。 2列2行

public Bitmap[][] splitBitmap(Bitmap bitmap, int xCount, int yCount) {
    // Allocate a two dimensional array to hold the individual images.
    Bitmap[][] bitmaps = new Bitmap[xCount][yCount];
    int width, height;
    // Divide the original bitmap width by the desired vertical column count
    width = bitmap.getWidth() / xCount;
    // Divide the original bitmap height by the desired horizontal row count
    height = bitmap.getHeight() / yCount;
    // Loop the array and create bitmaps for each coordinate
    for(int x = 0; x < xCount; ++x) {
        for(int y = 0; y < yCount; ++y) {
            // Create the sliced bitmap
            bitmaps[x][y] = Bitmap.createBitmap(bitmap, x * width, y * height, width, height);
        }
    }
    // Return the array
    return bitmaps;     
}
public Bitmap[][]拆分位图(位图位图,int-xCount,int-yCount){
//分配一个二维数组来保存单个图像。
位图[][]位图=新位图[xCount][yCount];
int宽度、高度;
//将原始位图宽度除以所需的垂直列计数
宽度=位图.getWidth()/xCount;
//将原始位图高度除以所需的水平行数
高度=位图.getHeight()/yCount;
//循环数组并为每个坐标创建位图
对于(整数x=0;x
回答时,你应该试着解释,而不是仅仅给出一段代码。请用一些文本来回答你的答案,说明你将来会做什么。这是有效的,但实际上,结果是图像的转置矩阵。