调整列表中图像的大小

发布于 2024-12-22 07:37:09 字数 170 浏览 1 评论 0原文

我有一堆图像显示在列表视图中(每行一个)。我拥有的图像文件的分辨率相当大,因此我需要将其缩小才能显示在列表视图中。

所以,我的问题是……存储两张图像(一张常规图像和一张缩略图)是否更快,因此无需动态缩放任何内容,或者简单地允许 Android 在创建列表时缩放此较大图像是否更快?

谢谢! 缺口

I have a bunch of images that are displayed in a list view (one per row). The image file I have is a pretty large resolution so I'll need to scale it down to be shown in the list view.

So, my questions is...is it faster to store two images (one regular and one thumbnail) so nothing has to be scaled on the fly OR is it faster to simply allow android to scale this larger image upon list creation?

Thanks!
Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-12-29 07:37:09

最佳方法取决于您的特定用例。如果您确实想将图像大小调整为缩略图级别(例如 150x150)并且不打算显示超过 30 个图像,则最好的方法是在内存中保留位图的缓存而不写入它们到磁盘(30 个图像大约需要 3 MB 内存)。这样,当您在屏幕上滚动图像时,ListView 就不会卡顿。当然,您可以保留完整版本并在用户点击 ListView 项目时显示该版本。

如果您想在 ListView 中显示更高分辨率的版本,那么您可能需要发挥创意。请记住,您没有太多时间来渲染每个单独的 ListView 单元格以保持平滑的滚动体验,并且解码大型图像文件将需要时间,即使您对其进行下采样并调整其大小;初始解码时间是相同的,唯一的区别是内存大小。在这种情况下,将原始版本和较小尺寸的版本都保留在磁盘中可能会很方便,以减少滚动时的卡顿。

The best approach depends on your particular use case. If you really want to resize the image to a thumbnail level (e.g. 150x150) and don't plan to have more than about a 30 images to display, the best approach would be to just keep a cache of the Bitmaps in memory without writing them to disk (at a cost of about 3 MB of memory for the 30 images). This way your ListView won't stutter while you scroll images in and out of the screen. You can of course keep the full version and display that when the user taps on the ListView item.

If you want to display a higher resolution version in the ListView, then you might have to get creative. Remember that you don't have much time to render each individual ListView cell to keep a smooth scrolling experience, and that decoding a large image file will take time, even if you're downsampling it and resizing it; the initial decoding time is the same, the only difference is the size in memory. In this case then it might be convenient to keep both the original and the smaller size version in disk to reduce the stuttering as you scroll.

淡墨 2024-12-29 07:37:09

存储两个图像,以避免用户不得不等待获取每个图像的完整尺寸,即使他们看到的只是缩略图,除非图像与应用程序捆绑在一起(即不是即时下载)。

Store two images to avoid your users having to wait to get the fullsize of every image even though all they're looking at are thumbnails, unless the images are bundled in with the app (i.e. not downloaded on the fly).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文