是否有可能砍位图以小件,而无需加载整个事情到内存? [英] Is it possible to chop a bitmap to small pieces without loading the entire thing into memory?
问题描述
我正在为Android的图像处理应用程序,识别来自拍摄音乐片,图片,音乐符号。
I'm working on an image processing application for Android that recognizes music notation from pictures taken of music sheets.
我试着用整个图像加载到一个位图的<一href="http://developer.android.com/reference/android/graphics/BitmapFactory.html#de$c$cFile%28java.lang.String%29">BitmapFactory.de$c$cFile(imgPath)方法,但因为我的手机没有足够的内存,我得到一个虚拟机堆大小的错误。要解决这个问题,我想砍完整的图像成小块,但我不知道该怎么做。
I tried to load the entire image into a Bitmap using the BitmapFactory.decodeFile(imgPath) method, but because my phone doesn't have enough memory I get a "VM heap size" error. To work around this, I'd like to chop the full image into smaller pieces, but I'm not sure how to do that.
我也看到了,这是可以通过使用<一个降低位图的内存大小href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize">inSampleSize在BitmapFactory.Option类的属性的,但如果我这样做,我不会得到我需要的音乐符号的识别过程的高分辨率图像。
I also saw that it was possible to reduce the memory size of the Bitmap by using the inSampleSize property of the BitmapFactory.Option class, but if I do that I won't get the high resolution image I need for the music notation recognition process.
反正是有处理这种没有去NDK?
Is there anyway to handle this without going to NDK?
推荐答案
安卓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.
您会如做到以下几点:
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(myStream, false);
Bitmap region = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);
易:)
这篇关于是否有可能砍位图以小件,而无需加载整个事情到内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!