异步图像加载和 android canvas
我目前正在开发一个使用可滚动/可缩放图像作为主用户界面的程序。它使用由矩阵操纵的画布来遍历大区域。我不想将超大位图加载到内存中,而是想使用平铺系统来加载 256 x 256 的方块。我的问题是,当图像加载到内存中时,应用程序会滞后。我使用简单的外部和内部 for 循环来加载图块(如果它们为空),并且如果用户缩小到一定程度,则图块全部消失并显示整个图像的较低分辨率版本。我已经转向异步图像加载的方向,这似乎可以防止图像加载到内存时出现延迟,但我不知道如何开始,并且想知道是否有人对如何异步加载位图有任何建议进入画布。谢谢!
Im currently developing a program that uses a scrollable/zoomable image as the main user interface. It uses a canvas which is manipulated by a matrix to traverse a large area. Instead of loading a super large bitmap into memory, i wanted to employ a tile system to load 256 by 256 squares. My problem is that the app will lag when the images are being loaded into memory. I use a simple outer and inner for loop to load the tiles if they are null, and if the user zooms out to a certain extent the tiles all disappear and a lower res version of the whole image is shown. Ive been steered into the direction of asynchronous image loading, which seems like it would prevent the lag while the image loads into memory but i have no idea how to start this, and was wondering if anyone had any advice on how to generally asynchronously load bitmaps into the canvas. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是使用第二个线程来做任何可能需要一些时间的事情,以确保 UI 始终良好且响应灵敏。如果 UI 包含动画(如滚动),您甚至可能想要降低该线程的优先级以消除卡顿。
您可以使用第二个 Thread 对象,该对象在完成后通过 Handler 发送消息,也可以使用 AsyncTask。
I simply use a second thread to do ANYTHING that could take some time to make sure that the UI is always nice and responsive. You may even want to lower the priority of that thread if the UI contains animation (like scrolling) to get rid of stuttering.
You could use a second Thread object that sends a message via a Handler when it's done, or you can use AsyncTask.