संक्षेप में, समस्या यह है कि जब आप BitmapFactory.decodeFile(String, Options)
का उपयोग करते हैं तो एंड्रॉइड options.inTempStorage
से स्वतंत्र रूप से 16 केबी BufferedInputStream
आवंटित करेगा।
अधिक विस्तृत होने के लिए: BitmapFactory.decodeFile(String, Options)
BitmapFactory.decodeStream(InputStream, Rect, Options)
के आसपास एक रैपर है जो FileInputStream
का उपयोग करता है। BitmapFactory.decodeStream(InputStream, Rect, Options)
के कार्यान्वयन में, वहाँ this code है:
public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) {
// ...
// we need mark/reset to work properly
if (!is.markSupported()) {
is = new BufferedInputStream(is, 16 * 1024);
}
// ...
}
के बाद से FileInputStream
के markSupported()
रिटर्न false
, इसका मतलब है कि options.inTempStorage
की स्वतंत्र रूप से, एक 16 kB बफर के साथ एक BufferedInputStream
अगर आप BitmapFactory.decodeFile(String, Options)
का उपयोग आप के लिए बनाया जाएगा।
इस 16 kB आवंटन से बचने के लिए, आप एक InputStream
जिसके लिए markSupported()
रिटर्न true
के साथ सीधे BitmapFactory.decodeStream(InputStream, Rect, Options)
उपयोग करने का प्रयास कर सकता है।
मैं दो विकल्प है कि में देख लायक हो सकता है के बारे में सोच सकते हैं:
- एक छोटे बफर
- उपयोग
AssetManager.AssetInputStream
रूप AssetManager.open(...)
द्वारा दिया के साथ अपने स्वयं BufferedInputStream
का उपयोग करें (यह कैसे उपयोग करने पर मेरा उत्तर here देखना)। इसका markSupported()
true
देता है।
पहला विकल्प अधिक मदद नहीं कर सकता है, आपके पास अभी भी एक बाइट [] सरणी आवंटित होगी, लेकिन कम से कम यह आपके नियंत्रण में है। दूसरा विकल्प सबसे उपयोगी साबित हो सकता है, यदि आपकी परिस्थितियां आपको इस दृष्टिकोण का उपयोग करने की अनुमति देती हैं।
स्रोत
2011-11-14 11:13:43