How do I save my imageView image into Gallery (Android Development)

前端 未结 5 2070
逝去的感伤
逝去的感伤 2021-01-05 17:01

I am trying to create an onClick event to save an imageview into the phone Gallery by the click of a Button, below is my code. it does not save into the Gallery, can anyone

5条回答
  •  时光取名叫无心
    2021-01-05 17:27

    I do this to save Image in gallery.

    private void saveImageToGallery(){
        imageview.setDrawingCacheEnabled(true);
        Bitmap b = imageview.getDrawingCache();
        Images.Media.insertImage(getActivity().getContentResolver(), b,title, description);
    }
    

    insertImage() will return a String != null if image has been really saved. Also: Needs permission in the manifest as "android.permission.WRITE_EXTERNAL_STORAGE" And note that this puts the image at the bottom of the list of images already in the gallery.

    Hope this helps.

提交回复
热议问题