我尝试在imageView中显示我创建的png文件。当我启动我的程序并点击showCreatedPng按钮时,模拟器屏幕上只有一个白色的空白页面。我的模拟器有200 MB的SD卡,但是,我找不到我的电脑中创建的PNG的位置。当我启动程序时,我的电话,PNG保存了在GT-I9100 \电话文件夹中。我猜的文件夹是一个内部文件夹中。无论如何,我看不到我创建PNG文件。请帮助。)Android从内部/外部存储获取图像
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)
这些是我使用的代码。
为了节省:
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());
}
}
与代码得到png文件:
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);
感谢您的帮助。
Thaks很多:D有时我看不到像这样的小东西。 :d –