Android 7'deki Asset dizininden bitmapler kodu nasıl çözülür?BitmapFactory.decodeStream öğesinden Gelen Değerler, Android 7'de null değerini döndürüyor
Uygulamam, Android sürümlerinde Marshmallow'a kadar iyi çalışıyor. Android 7 ile, Asset dizinindeki görüntüleri yüklemek başarısız oluyor.
Benim Kod:
private Bitmap getImage(String imagename) {
// Log.dd(logger, "AsyncImageLoader: " + ORDNER_IMAGES + imagename);
AssetManager asset = context.getAssets();
InputStream is = null;
try {
is = asset.open(ORDNER_IMAGES + imagename);
} catch (IOException e) {
// Log.de(logger, "image konnte nicht gelesen werden: " + ORDNER_IMAGES + imagename);
return null;
}
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, PW, PH);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
// Lesen des Bitmaps in der optimierten Groesse
return BitmapFactory.decodeStream(is, null, options);
}
Sonuç olarak (yalnızca Android 7) BitmapFactory.decodeStream
boş. Eski bir Android API'ları doğru şekilde çalışıyor.
döndürdü: 50,384 6274-6610/myapp D/Skia aşağıdaki Mesaj olmadığını ayıklama modunda09-04 10: 10: --- SkAndroidCodec :: NewFromStream boş
Birisi bana nedenini ve kodlamayı nasıl düzeltebilir?
Düzenleme: Bu arada, ilk BitmapFactory.decodeStream öğesinin inJustDecodeBounds = true ile kaldırılmasının, daha sonra inJustDecodeBounds = false ile başarılı bir BitmapFactory.decodeStream yol açtığını buldum. Nedeni bilmemek ve bitmap boyutunun ölçümünü nasıl değiştireceğinizi bilmemek.
Tahminim, sorununuzun varlığınıza özel olması. Sadece Android 7.0 çalıştıran bir Nexus 9'da [resim kitaplığımdan biri] (https://github.com/commonsguy/cw-omnibus/tree/master/Bitmaps/InSampleSize) testlerini öğelerden yükledim. İyi çalışıyor gibi görünüyor. – CommonsWare