मैं कैमरे के रूप में पुनर्प्राप्त छवियों के आकार को कम करने की कोशिश कर रहा हूं (इसलिए ~ 5-8 मेगा पिक्सल) नीचे कुछ छोटे आकारों (सबसे बड़ा 1024x768) है। मैंने निम्नलिखित कोड का प्रयास किया लेकिन मुझे लगातार OutOfMemoryError
मिल गया।एंड्रॉइड में मेमोरी कुशल छवि का आकार
Bitmap image = BitmapFactory.decodeStream(this.image, null, opt);
int imgWidth = image.getWidth();
int imgHeight = image.getHeight();
// Constrain to given size but keep aspect ratio
float scaleFactor = Math.min(((float) width)/imgWidth, ((float) height)/imgHeight);
Matrix scale = new Matrix();
scale.postScale(scaleFactor, scaleFactor);
final Bitmap scaledImage = Bitmap.createBitmap(image, 0, 0, imgWidth, imgHeight, scale, false);
image.recycle();
ऐसा लगता है कि ओओएम createBitmap
के दौरान होता है। क्या ऐसा करने के लिए एक और अधिक मेमोरी प्रभावी तरीका है? शायद कुछ ऐसा जो मुझे पूरे मूल को स्मृति में लोड करने की आवश्यकता नहीं है?
नहीं, मैं 'android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI' उपयोग कर रहा हूँ उपयोगकर्ता एक चित्र का चयन करते हैं। – Sionide21