How to load tiles from a large bitmap in Android?

前端 未结 3 1666
悲&欢浪女
悲&欢浪女 2020-12-03 04:25

If I have a large bitmap file that would normally generate an \"Out of memory\" exception, how can I load it as tiles? e.g. I have a 10,000x10,000 image, I want to split it

3条回答
  •  感动是毒
    2020-12-03 04:45

    If the image is stored as a compressed bitmap, then it's virtually impossible to calculate where a particular region of the image is located in the file. To find a particular region, you would decode line by line, throwing away the results until you get to row y. You then continue decoding for height rows, throwing away the pixels to the left of your X coordinate and to the right of X+width.... very slow if you're panning across the bottom of a large bitmap.

    Reading between the lines, it appears that the BitmapRegionDecoder() mentioned earlier does this in the background if 'isShareable' is true. Otherwise it seems that it may uncompress the image, and store the uncompressed copy. With 1 byte per pixel, it will take 100MB to hold your 10,000x10,000 bitmap.

提交回复
热议问题