图像未保存在图库中

时间:2014-04-19 15:10:21

标签: android image imageview save

我使用此代码保存图像:

mImageView.buildDrawingCache();
Bitmap bmap = mImageView.getDrawingCache();
OutputStream fOut = null;
Uri outputFileUri;
try {
    File root = new File(Environment.getExternalStorageDirectory()
    + File.separator + "folder_name" + File.separator);
    root.mkdirs();
    File sdImageMainDirectory = new File(root, "myPicName.jpg");
    outputFileUri = Uri.fromFile(sdImageMainDirectory);
    fOut = new FileOutputStream(sdImageMainDirectory);
           } 
catch (Exception e) {
            Toast.makeText(this, "Error occured. Please try again later.",
              Toast.LENGTH_SHORT).show();
           }

try {
            bmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            fOut.flush();
            fOut.close();
           } 
catch (Exception e) {
           }

这样,图像将保存在手机中,但在手机图库中不可见。怎么会这样?然后我想知道如何保存到内部存储器而不是SD卡。感谢。

1 个答案:

答案 0 :(得分:0)

将图像保存到Android图库的最简单方法是:

MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, imageTitle, imageDescriprion);

并将Android权限添加到AndroidManifest:

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