我使用这段代码保存图像:保存图像库的Android
URL url = null;
try {
url = new URL("image");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e1) {
e1.printStackTrace();
}
OutputStream output;
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/folder name/");
dir.mkdirs();
File file = new File(dir, image + ".png");
Toast.makeText(HomeActivity.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
try {
output = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
}
catch (Exception e) {
e.printStackTrace();
}
当这个程式码棒棒糖设备上运行的问题是,图像不能在画廊展示。我必须安装文件管理器来检查这些图像。
有了这个代码:
MediaStore.Images.Media.insertImage(getContentResolver(), bmp, "image";
保存图像的相机文件夹中。
我想在所有的Android设备中显示具有特定文件夹名称的图库中的图像。
请帮忙。
您需要在图库中添加图像后刷新图库。 刷新库: http://stackoverflow.com/questions/4144840/how-can-i-refresh-the-gallery-after-i-inserted-an-image-in-android –
@VipulPatel:sendBroadcast( (Intent.ACTION_MEDIA_MOUNTED,Uri.parse (“file://” + Environment.getExternalStorageDirectory()))); 文件是文件路径吗? – android
你需要引用这个链接你的问题: http://stackoverflow.com/questions/3300137/how-can-i-refresh-mediastore-on-android –