如何将位图也划分为位图 [英] How to divide a bitmap into parts that are bitmaps too

查看:107
本文介绍了如何将位图也划分为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello StackOverflow社区. 我需要一些有关将位图分成小块的可能方法的信息. 更重要的是,我将需要一些选择来进行判断.我已经检查了很多帖子,但是我仍然不完全相信该怎么做.

Hello StackOverflow comunity. I need some info on the possible methods for dividing a bitmap in smaller pieces. More importantly i would need some options to judge. I have checked many posts and I am still not entirely convinced about what to do.

剪切位图的一部分

如何切割中间部分位图的区域?

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

These two links are some good options i found , but i cant calculate the CPU and RAM cost of each method, or maybe i should not bother with this calculation at all. Nonetheless if I am about to do something , why not do it the best way from the start.

我很高兴获得有关位图压缩的一些技巧和链接,因此也许我可以结合使用这两种方法来获得更好的性能.

I would be grateful to get some tips and links on bitmap compression so maybe i get better performance combining the two methods.

我先谢谢你.

推荐答案

此功能允许您将位图拆分为行和列,并拆分行和列的数量.

This function allows you to split a bitmap into and number of rows and columns.

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

Example Bitmap[][] bitmaps = splitBitmap(bmp, 2, 1); Would create a vertically split bitmap stored in a two dimensional array. 2 columns 1 row

示例Bitmap [] []位图= splitBitmap(bmp,2,2); 将一个位图分成存储在二维数组中的四个位图. 2列2行

Example Bitmap[][] bitmaps = splitBitmap(bmp, 2, 2); Would split a bitmap into four bitmaps stored in a two dimensional array. 2 columns 2 rows

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

这篇关于如何将位图也划分为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆