我想将我的裁剪照片从imageView存储到我的私人文件夹中

时间:2014-02-20 11:02:10

标签: java android imageview image-gallery

目前,这样做只会将其存储到图库中。我不知道如何将裁剪的照片保存到我自己的文件夹中。

我的问题是:

如何将文件保存到我的本地文件夹?

case CROP_FROM_CAMERA:          
            Bundle extras = data.getExtras();

            Bitmap photo = null;

            if (extras != null) {               
                photo = extras.getParcelable("data");

                mImageView.setImageBitmap(photo);
            }

            // Create new folder inside Palm Detect directory
            File mediaStorageDir2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "Palm Detect",
                    "Cropped Image");


            // Create the storage directory if it does not exist
            if (!mediaStorageDir2.exists()) {                       
                if (!mediaStorageDir2.mkdirs()) {
                    Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
                            + "Cropped Image" + " directory");
                }
            }
            // Store cropped photo into gallery
            Images.Media.insertImage(getContentResolver(), photo, "Img_" + String.valueOf(System.currentTimeMillis()), "");




            break;

1 个答案:

答案 0 :(得分:2)

您需要通过执行此操作添加本地文件

 try {

  mediaStorageDir2.createNewFile();

  FileOutputStream ostream = new FileOutputStream(mediaStorageDir2);
  photo.compress(CompressFormat.PNG, 10, ostream);
  ostream.flush();
  ostream.close();

  System.gc();

  } catch (Exception e) {
    e.printStackTrace();
}

修改:您还需要为AndroidManifest.xml添加权限

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