Transfer paint / draw / save multiple bitmaps

Goal:

I want to draw / write / draw bitmaps from pdf and save them together so that I can send them email.

Details:

I have several Pdf files containing 5-20 pages each, right now I am extracting bitmap images from pdfs and loading them into fragments in ViewPager , where I can transfer through them and write / draw or whatever I want. To save / restore the current state of the bitmap, I use onSaveInstanceState . That way, I can get the last stage of the bitmap while you switch back and forth.

Something like that:

 @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable("Bitmap", bitmap); } 

Problem:

The user clicks the send email button, and I should be able to save all the images no matter what page it is on, i.e. he edited pages 5 to 10 and now he is on page 10 and press the submit button, I have to get all the edited images.

Problem 2:

As I said, the number of images is about 5-20, saving the state in onSaveInstanceState works fine, but it continues to increase the application memory in ram, and the application drops in the 10th image, where the application size goes to 150Mbs .

But saving the image as a package in onSaveInstanceState also necessary, as it helps speed up the loading of images when the user bounces back.

So, I was thinking, is there a way to create a custom class package where we can write an image to disk, say, 5 scroll pages and clear the memory and read it from disk to memory when the user scrolls back? does that sound reasonable?

What I tried:

As raster images are loaded into separate fragments, I tried to save bitmaps to external storage in OnDestroy , but since saving raster images to disk is not a small task, it takes time, although I use AsyncTask but when a user quickly AsyncTask over a bit between fragments, saving raster images in OnDestroy does not seem to be a convenient way.

That’s why I ask the question, so maybe you better understand the situation and can help me achieve this in a more convenient way.

So what are you doing, how can I deal with this situation?

Note:

If you have problems understanding the situation and need more information, leave me a comment and I will update the question.

thanks

+6
source share
1 answer

Let me describe how I see a solution to this problem now.

There must be a Service that accepts the bitmap edited with some identifier (the same for all modifications of the original bitmap), adds it to the queue, and then each element of this queue saves external storage. It has a limited instance of Executor that performs these tasks (they can just be Runnable ), and Service creates a HashMap where it maps Future tasks to a bit identifier. Therefore, when a new Bitmap appeared, Service checks the map and replaces the pending task (with the same source bitmap), if any.

You can send a task to this Service from the destroyItem interceptor FragmentStatePagerAdapter .

So, when the user clicks the save button, you should also send all edited bitmaps left before this Service , and just wait for the completion.

0
source

Source: https://habr.com/ru/post/1011501/


All Articles