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

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

问题描述

如果我有一个通常会产生记忆出异常大的位图文件,我怎么能装载它的瓷砖?例如我有一个10,000x10,000的形象,我想将其分割成1,000x1,000像素砖一10×10的网格。

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,宽,高),但它需要我大的图像作为源输入。

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

我怎样才能得到一个tile从我的输入图像,而不完全加载输入图像?​​

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

推荐答案

从罗曼盖伊回答<一href="http://stackoverflow.com/questions/4815192/is-it-possible-to-chop-a-bitmap-to-small-pieces-without-loading-the-entire-thing/4903455#4903455">Is可以砍位图以小件,而无需加载整个事情到内存:

安卓2.3.3有一个新的API,称为   android.graphics.Bitma pregionDe codeR   这让你做什么你   想要的。

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

您会如做   以下内容:

You would for instance do the following:

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

     

简单:)

Easy :)

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

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