我在drawable文件夹中保存了几张壁纸。我想将这些图像保存在壁纸文件夹中。现在我的图像被保存在相机文件夹中。使用此代码。
Bitmap w1 = BitmapFactory.decodeResource(getResources(),
R.drawable.wallpaper03);
Images.Media.insertImage(getApplicationContext().getContentResolver(),
w1, "", "");
答案 0 :(得分:1)
我理解你的问题 你需要内存中的壁纸目录 你需要将可绘制的图像保存到该目录
创建壁纸目录或文件夹(如果不存在) Create folder in Android
如何将图像从可绘制内容保存到手机内存save image to device memory
答案 1 :(得分:1)
Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
可以使用以下方法检索SD卡的路径:
String extStorageDirectory = Environment.getExternalStorageDirectory().toString()+"/FOLDERNAME/";
然后使用以下按钮单击按钮保存到SD卡:
File file = new File(extStorageDirectory, "ic_launcher.PNG");
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
不要忘记添加 android.permission.WRITE_EXTERNAL_STORAGE
权限。
完整的示例项目: SAMPLE PROJECT
答案 2 :(得分:1)
void Save(){
String folder = "/sdcard/Pictures/MyAppFolder";
Imageview view = (ImageView)findViewById(R.id.cachesView);
view.buildDrawingCache();
Bitmap yourBitmap = view.getDrawingCache();
final File myDir = new File(folder);
myDir.mkdirs();
final Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
final String fname = "StyleMe-" + n + ".png";
File file = new File(myDir, fname);
if (file.exists())
FileOutputStream out = new FileOutputStream(file);
yourBitmap.compress(CompressFormat.JPEG, 100, out);
out.flush();
out.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory()))); // this will refresh the gallery app.
Toast.makeText(getApplication(), "Image Saved", Toast.LENGTH_SHORT)
.show();
}
在您的课程中添加此方法,然后点击按钮
Save();
see here 回答