Halil Cosgun Halil Cosgun - 2 months ago 20
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() + "/";
try
{
File dir = new File(qrPath);
if (!dir.exists()) {
dir.mkdirs();
}
OutputStream fOut = null;
File file = new File(qrPath, "QRCode.png");
if(file.exists()){
file.delete();
file.createNewFile();
fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
}
}
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);

setContentView(R.layout.qr_image);
ImageView imageView = (ImageView) findViewById(R.id.qr_image);
imageView.setImageBitmap(mustOpen);


Thanks for your help.

Answer

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

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