Halil Cosgun Halil Cosgun - 4 months ago 40
Android Question

Android get image from internal/external storage

I try to show my created png file in an imageView. When I start my program and click the showCreatedPng button, there is just a white blank page on emulator's screen.

And logCat says : (Maybe Logcat shows errors because of Emulator. My emulator has 200 mb sd-card but, I can not find where is the created PNG in my computer. When I start the program my phone, PNG saved in GT-I9100\Phone folder. I guess the folder is an internal folder. Anyway, I can not see my created png file. Please help.)

05-21 21:53:39.764: E/BitmapFactory(1335): Unable to decode stream: java.io.FileNotFoundException: /mnt/sdcard/*.png: open failed: ENOENT (No such file or directory)

These are codes that I used.

For saving :

private void saveImageToExternalStorage(Bitmap bitmap) {
String qrPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
File dir = new File(qrPath);
if (!dir.exists()) {
OutputStream fOut = null;
File file = new File(qrPath, "QRCode.png");
fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
catch (Exception e) {
Log.e("saveToExternalStorage()", e.getMessage());

And codes for get png file :

String qrPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/*.png";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap mustOpen = BitmapFactory.decodeFile(qrPath, options);

ImageView imageView = (ImageView) findViewById(R.id.qr_image);

Thanks for your help.


You are trying to open a file called *.png. This should probably be QRCode.png, thus the code

Environment.getExternalStorageDirectory().getAbsolutePath() + "/QRCode.png";