如何从 Android 中的大位图加载图块? [英] How to load tiles from a large bitmap in Android?

查看:29
本文介绍了如何从 Android 中的大位图加载图块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个通常会产生内存不足"异常的大位图文件,我如何将它作为图块加载?例如我有一张 10,000x10,000 的图像,我想将其拆分为 1,000x1,000 像素图块的 10x10 网格.

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 up into a 10x10 grid of 1,000x1,000 pixel tiles.

我见过函数 Bitmap.createBitmap(sourceBitmap, x, y, width, height) 但它需要我的大图像作为源输入.

I've seen the function Bitmap.createBitmap(sourceBitmap, x, y, width, height) but it requires my large image as the source input.

如何在不完全加载输入图像的情况下从输入图像中获取图块?

How can I get a tile from my input image, without fully loading the input image?

推荐答案

Romain Guy 在 是否可以将位图切割成小块而不将整个事物加载到内存中?:

Answer from Romain Guy in Is it possible to chop a bitmap to small pieces without loading the entire thing into memory?:

Android 2.3.3 有一个名为的新 APIandroid.graphics.BitmapRegionDecoder这让你可以做你想做的事想要.

Android 2.3.3 has a new API called android.graphics.BitmapRegionDecoder that lets you do exactly what you want.

例如你会做以下:

BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(myStream, false);  
Bitmap region = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);

简单:)

这篇关于如何从 Android 中的大位图加载图块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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