Android 将位图另存为Genymotion中的图像

Android 将位图另存为Genymotion中的图像,android,bitmap,genymotion,Android,Bitmap,Genymotion,我知道以前可能会有人问这个问题,我尝试过这里给出的所有答案,但都不起作用。 我从gallery中选取一幅图像,显示它,然后更改一些像素并尝试将其保存在sd卡中,但它没有保存。 布局: <Button android:id="@+id/pick_image_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pick Ima

我知道以前可能会有人问这个问题,我尝试过这里给出的所有答案,但都不起作用。 我从gallery中选取一幅图像,显示它,然后更改一些像素并尝试将其保存在sd卡中,但它没有保存。 布局:

<Button
    android:id="@+id/pick_image_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Pick Image" />

<ImageView
    android:id="@+id/image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
保存图像的代码(不是完整代码,而是保存图像的部分)


我已在清单文件中添加了权限,但它不起作用“

-什么不起作用?图像保存后不会显示在库中。我已在下一句中对此进行了解释。
Button buttonLoadImage = (Button) 
rootView.findViewById(R.id.pick_image_button);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {

   Intent i = new Intent(Intent.ACTION_PICK);
   File pictureDirectory= 
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS);
   pictureDirectoryPath=pictureDirectory.getPath();

   Uri data=Uri.parse(pictureDirectoryPath);
   i.setDataAndType(data,"image/*");
   startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK
           ) {

        try{
         imageUri = data.getData();
        Uri selectedImage = data.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};
        Cursor cursor = 
              getActivity().getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        picturePath = cursor.getString(columnIndex);
        cursor.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
            Utility.showCustomAlert(picturePath,getActivity(),"error");


        imageView = (ImageView) rootView.findViewById(R.id.image_view);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

   try{
       inputstream = 
           getContext().getContentResolver().openInputStream(imageUri);
       Bitmap bmp = BitmapFactory.decodeStream(inputstream);
        imageView.setImageBitmap(bmp);
      }
   catch (Exception e)
    {
           e.printStackTrace();
     }
}
 String sdCardDirectory = 
 Environment.getExternalStorageDirectory().getAbsolutePath();
 File dir = new File(sdCardDirectory+ "/download");
 dir.mkdirs();
 String fname="imazh.png";
 File file=new File(dir,fname);
 if(file.exists())file.delete();


 // Encode the file as a PNG image.
 FileOutputStream outStream;

      outStream = new FileOutputStream(file);
      bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
      outStream.flush();
      outStream.close();
      success = true;
      MediaScannerConnection.scanFile(getContext(),
                    new String[] { file.toString() }, null,
                    new MediaScannerConnection.OnScanCompletedListener() {
                        public void onScanCompleted(String path, Uri uri) {

                        }
                    });