Ich versuche, die Breite und Höhe eines Bildes zu erhalten, um es zu rezizieren, falls es zu groß ist, bevor es angezeigt wird. Meine Methode empfängt eine Uri des Bildes, aber ich bekomme immer eine FileNotFoundException, wenn ich versuche, sie mit BitmapFactory zu entschlüsseln. HierAndroid: FileNotFoundException beim Versuch, ein Bild von Uri
ist eine Probe von meinem Code:
Uri myUri;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(new File(myUri.getPath()).getAbsolutePath(), options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
Decode Datei kehrt wirft ein FileNotFoundException hier. Allerdings kann ich zeigen noch das Bild mit der uri ohne eine Bitmap-Fabrik mit diesem mit:
Uri myUri;
Bitmap myBitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), myUri);
Das Problem mit diesem Code ist, dass das zurückgegebene Bitmap möglicherweise eine OutOfMemoryError verursachen, wenn große Bilder verwenden.
Wenn ich meine Uri debuggen, bekomme ich diese:
Inhalt: //com.android.providers.media.documents/document/image%3A20472
UPDATE || Hier ist der Arbeitscode
Uri myUri;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// This is the part that changed
InputStream inputStream = context.getApplicationContext().getContentResolver().openInputStream(myUri);
BitmapFactory.decodeStream(inputStream,new Rect(),options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
All dies natürlich von Versuch/Fang umgeben.
Es ist eine Weile her, seit ich mit Android gespielt habe, aber da es eine FileNotFoundException ist, haben Sie versucht, "new File (myUri.getPath()). GetAbsolutePath()" zu überprüfen, welcher Wert genau zurückgibt? Da könnte etwas komisches vor sich gehen. – hennign
Benötigen Sie weitere Informationen zu myUri? Ich kann nicht herausfinden, was Inhalt: //com.android.providers.media.documents/document/image%3A20472 in diesem Zusammenhang bedeutet. – hennign