Save Image android

1

I know that there is probably an answer here on the site for my question, but when I looked I saw a lot of shapes and I was kind of lost.

I wanted to create a hidden folder and have some ImageButton or something so I can select an image from the gallery (do not open the camera and take a photo at the time) and copy (without deleting the original image) / p>

I also need to resize this image if the selected image is very large, in the tests I did, the image was very large and covered a lot of the screen, and even covering other things, only part of the image appeared, to try to solve this problem I put a fixed size in the ImageButton , so it did not cover the rest of the screen but it cut the image (it only showed one piece)

By the tests I've done, I imagine you should be creating a Intent to open the gallery with a return, in that return you get the URI of the image and transform that URI into a path, so that you can copy it to another folder, and then in the folder transform the image into bitmap , to be able to resize and then transform the bitmap into URI to save the path in the bank to then set using setImageUri() in the rest of the application (in ImageView ImageButton ), however if the user cancels or, in the future, delete the file, it would also be necessary to delete the moved image file to the created folder

Another question, what is the best way to get this image? With ImageView , ImageButton or what, if it has any pattern?

I saw several questions that answer to this but home question answered a part and when I was joined I could not, can anyone help?

If you know of a question that does this please pass the link

    
asked by anonymous 28.10.2017 / 23:25

1 answer

1

I'll leave you a list of points here, which will answer your question. Implementations are examples in libraries. These are all libraries I used in a project, the only thing different from yours was that I needed to load and save the resized image in a firebase storage.

  

I wanted to create a hidden folder and have some ImageButton or something so I can select an image from the gallery (do not open the camera and take a photo in time) and copy (without deleting the original image) to the created folder. p>

Create a folder in the application's internal storage. Remembering that this folder would not be available to other apps, just for yours.

File dir = context.getDir("DiretorioLindo", Context.MODE_PRIVATE);
if (!dir.exists())
    dir.mkdirs();
  

I also need to resize this image if the selected image is too large

Uses the library Compressor , which resizes and compresses the image as needed

  

Capturing the user's image

Use the library Android-Image-Cropper , it shows a UI to select from where the user wants to image, and also gives you the opportunity to crop the image and modify it before saving.

Remembering that all permissions handling and new ways to read files on Android 7+ should be respected.

    
06.11.2017 / 11:31