简体   繁体   English

什么是保存/加载位图的有效方法

[英]What is the efficient way for saving/loading Bitmaps

I'm working on an app that can be used for taking notes, simply a drawing application which is keeping bunch of Bitmap objects. 我正在开发一个可用于做笔记的应用程序,只是一个保留了许多位图对象的绘图应用程序。 I completed creating those pages(Bitmap) and drawing part but i have trouble with memory management, i dynamically create Bitmap object as full screen (for ex; 1280x720) resolution then working on it. 我已完成创建这些页面(位图)和绘图部分的操作,但是我在内存管理方面遇到了麻烦,我以全屏(例如1280x720)分辨率动态创建位图对象,然后对其进行了处理。

Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)

When user starts to create new pages, normally memory keeps growing. 当用户开始创建新页面时,通常内存会不断增长。 Some point i'm getting "Out of memory" error then my application is crashing. 有时我遇到“内存不足”错误,然后我的应用程序崩溃了。

In my application user can navigate between pages with scrolling and can see maximum two pages at a time (partial pages). 在我的应用程序中,用户可以滚动浏览页面,并且一次最多可以看到两页(部分页面)。 I wonder if there any existing API for saving those Bitmap objects which is not displayed at that moment and unload from memory and loading those Bitmap objects when need to display. 我想知道是否存在用于保存那些当时未显示的位图对象并从内存中卸载并在需要显示时加载那些位图对象的现有API。 If there is no existing API can you give me some ideas how can i write my own Memory manager, how i must save those Bitmaps and where ? 如果没有现有的API,您可以给我一些想法,如何编写自己的内存管理器,如何保存这些位图以及在哪里保存?

For example ; 例如 ; User start to create new pages 1-2-3-4 right now i just need show page4 on the screen i don't need to keep page1-2 (page3 could be in memory for smooth transition ?) in memory i need to save it to disk (or encode as PNG ? or any better solution ? ) When user start to scrolling up that means i need to show page3-page4 at the same time (Maybe i also need to load page2 at this moment to Memory for smooth scrolling), so my app works as like that. 用户现在开始创建新页面1-2-3-4,我只需要在屏幕上显示page4,就不需要在内存中保留page1-2(page3可以在内存中以进行平滑过渡?),我需要保存它到磁盘上(或编码为PNG?或其他更好的解决方案?)。当用户开始向上滚动时,这意味着我需要同时显示page3-page4(也许我现在还需要将page2加载到内存中才能平滑滚动) ),因此我的应用程序就是这样。

You should use multi threading methods and associate them with async task. 您应该使用多线程方法,并将它们与异步任务相关联。 Take a look here https://developer.android.com/training/multiple-threads/run-code.html 在这里看看https://developer.android.com/training/multiple-threads/run-code.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM