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:
These two posts 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.
Example Bitmap[][] bitmaps = splitBitmap(bmp, 2, 1); Would create a vertically split bitmap stored in a two dimensional array. 2 columns 1 row
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With