Save android image

Asked

Viewed 1,765 times

1

I know there’s probably an answer here on the site to my question, but when I researched I saw several ways and got a little lost.

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

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 much 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 on ImageButton, so did not cover the rest of the screen but cut the image (showed only a piece)

From the tests I’ve done I imagine it must be creating a Intent to open the gallery with return, in this return take the URI image and transform that URI in a path, to be able to copy to another folder, and in the folder turn the image into bitmap, to be able to resize and then transform the bitmap in URI to save the path in the bank and then set using setImageUri() in the rest of the application (in ImageView and ImageButton), but in case the user cancels or, in the future, delete the registration, it would also be necessary to delete the image file moved to the created folder

Another question is, what is the best way to get this image? With a ImageView, ImageButton or what, if there are any patterns?

I saw several questions that answer this but house question answered a part and when I went to gather I could not, someone can help?

If you know a question that does so please pass the link

  • 1

    Your question is very broad and focuses on many issues. There is no answer here to answer all of this. However there are answers that answer, individually, to each of the subjects. You just want to search.

1 answer

1


I will leave here a list of points, which will answer your question. Implementations exist examples in libraries. They’re all libraries I used in a project, that the only thing different from yours was that I needed to upload and save the resized image in a firebase archive.

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

Creates a folder in the application’s Interstate. Remembering that this folder would not be available for other apps, only for your.

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

Use the library Compressor, that it resizes and compresses the image as needed

Capture the user image

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

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

  • I took a look at the library and you used the setDestinationDirectoryPath() to send the image to a directory, but deletes the original file? If it doesn’t delete, does it keep the same as the original or changes? And what would those methods be .subscribeOn(), .observeOn() and .subscribe()?

  • 1

    Do not delete the original as it will save the captured/selected image and then cut in that directory. subscribes On() is only if you use Rxjava. But use the traditional methods without them.

  • Thanks help a lot, would send the code of your application, later I will make an application similar to this but registering in firebase. Thank you

  • Unfortunately I can not, for reasons of copyright, but if you have any questions you will post here that we will answer.

  • I understand, thanks for the help, I took a while to give the reward because I had no time to test the code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.