Android 位图图像与图像存储的若干问题

Android 位图图像与图像存储的若干问题,android,imageview,bitmapimage,Android,Imageview,Bitmapimage,我有从我的相机活动中得到的位图图像。有人能告诉我如何在画廊中储存这张照片吗 代码: 在我的按钮中,单击侦听器 Intent campic=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(campic,cameradata ); 在我的onActivityResult中 if(resultCode==RESULT_OK) {

我有从我的相机活动中得到的位图图像。有人能告诉我如何在画廊中储存这张照片吗

代码:

在我的按钮中,单击侦听器

    Intent campic=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(campic,cameradata ); 
在我的onActivityResult中

        if(resultCode==RESULT_OK)
        {
           Bundle bun=data.getExtras();
           bmp=(Bitmap)bun.get("data");
           SaveIamge(bmp);
           iveventpic.setImageBitmap(bmp);
        }

所示,调用此函数将位图保存在SD卡中:

private void SaveIamge(Bitmap finalBitmap) {

String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");    
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete (); 
try {
       FileOutputStream out = new FileOutputStream(file);
       finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
       out.flush();
       out.close();

} catch (Exception e) {
       e.printStackTrace();
}
}
通过拨打此电话,您必须将该图像存储在多媒体资料中:

sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
        Uri.parse("file://" + Environment.getExternalStorageDirectory())));
并在清单中添加权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 


[此链接][1]可能正是您要查找的内容。[1] :如果保存到gallery,则除非发送广播(新的Intent(Intent.ACTION\u MEDIA\u MOUNTED,Uri.parse(“file://“+Environment.getExternalStorageDirectory())),否则下次打开手机时才会显示它;它起作用了:)但画廊并没有立即显示图像。是否在固定的时间间隔后参考画廊?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />