@RKN
Yöntemin ayrıca istisna OutOfMemoryError atabilir denemek kullanmak - kırpılmış bitmap VM aşarsa.
My yöntem bu exeption karşı sizin ve koruma birleştirir: (l, t, r, b - resmin%)
Bitmap cropBitmap(ContentResolver cr, String file, float l, float t, float r, float b)
{
try
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// First decode with inJustDecodeBounds=true to check dimensions
BitmapFactory.decodeFile(file, options);
int oWidth = options.outWidth;
int oHeight = options.outHeight;
InputStream istream = cr.openInputStream(Uri.fromFile(new File(file)));
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(istream, false);
if (decoder != null)
{
options = new BitmapFactory.Options();
int startingSize = 1;
if ((r - l) * oWidth * (b - t) * oHeight > 2073600)
startingSize = (int) ((r - l) * oWidth * (b - t) * oHeight/2073600) + 1;
for (options.inSampleSize = startingSize; options.inSampleSize <= 32; options.inSampleSize++)
{
try
{
return decoder.decodeRegion(new Rect((int) (l * oWidth), (int) (t * oHeight), (int) (r * oWidth), (int) (b * oHeight)), options);
}
catch (OutOfMemoryError e)
{
Continue with for loop if OutOfMemoryError occurs
}
}
}
else
return null;
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
ve maksimum kullanılabilir bitmap veya null
Teşekkürler Steve, ancak bu önce sourceBitmap'e yüklememi gerektirir ve bunu yapmaktan kaçınmaya çalışıyorum, çünkü belleğe sığmayacak kadar büyüktür ve alt örneklemede olmayan bir bitmap ile çalışmak istiyorum. . – Schermvlieger
Oops, haklısın, sorununun bu bölümünü düzgün okumadım. Bundan sonra altörneklemesiz olarak nasıl yapılacağından emin değilim. Aslında çok benzer bir problem, kendi başıma nasıl yapılacağına dair bir liste. –