图像未显示在活动中

时间:2017-11-24 05:33:10

标签: android

我正在操作一个文件夹中的图像并将其保存在内部存储器中的其他文件夹中。另一个活动显示所有图像都需要我正在操作的图像,但图像保存在内部存储器中,因为我可以通过文件检查它经理。

Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
listItem = new ArrayList<ImageItem>();
cursor.moveToFirst();

1 个答案:

答案 0 :(得分:0)

    //Pick image. 
    Uri selectedImage = data.getData();
                    String[] filePathColumn = {MediaStore.Images.Media.DATA};

                    Cursor cursor = getContentResolver().query(selectedImage,
                            filePathColumn, null, null, null);
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String picturePath = cursor.getString(columnIndex);
                    cursor.close();

    // method for save image
private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) {

    File direct = new File(Environment.getExternalStorageDirectory() + "/Folder Name");
    File file = new File(direct);
    if (!file.exists()) {
        file.mkdir();
    }
 file = new File(file, fileName);
    try {
        FileOutputStream out = new FileOutputStream(file);
        imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}