我尝试将图像保存到WathsappIMG中,但当我转到图片库android时,我看不到图像,并且可以从ES文件资源管理器中看到目录中的图像
OutputStream output;
// Find the SD Card path
File filepath = Environment.getExternalStorageDirectory();
// Create a new folder in SD Card
File dir = new File(filepath.getAbsolutePath()
+ "/WhatSappIMG/");
dir.mkdirs();
// Retrieve the image from the res folder
BitmapDrawable drawable = (BitmapDrawable) principal.getDrawable();
Bitmap bitmap1 = drawable.getBitmap();
// Create a name for the saved image
File file = new File(dir, "Wallpaper.jpg" );
try {
output = new FileOutputStream(file);
// Compress into png format image from 0% - 100%
bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, output);
output.flush();
output.close();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
发布于 2015-01-28 13:31:39
以下是您在要将图片保存到图库时应输入的内容
MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);
该代码将在图库的末尾添加图像。因此,请检查您的画廊图片,以确保
发布于 2013-12-31 23:49:21
尝试添加以下内容:
MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);
填写yourBitmap、yourTitle和yourDescription的详细信息,或者将其保留为""
。
发布于 2018-07-26 22:14:04
对于Xamarin研究员:
public static void SaveToTheGalley(this string filePath, Context context)
{
var values = new ContentValues();
values.Put(MediaStore.Images.Media.InterfaceConsts.DateTaken, Java.Lang.JavaSystem.CurrentTimeMillis());
values.Put(MediaStore.Images.Media.InterfaceConsts.MimeType, "image/jpeg");
values.Put(MediaStore.MediaColumns.Data, filePath);
context.ContentResolver.Insert(MediaStore.Images.Media.ExternalContentUri, values);
}
别忘了android.permission.WRITE_EXTERNAL_STORAGE
权限。
https://stackoverflow.com/questions/20859584
复制相似问题