简体   繁体   English

Android 上的滑动膨胀图像问题

[英]Issues with glide bloating images on Android

I'm debugging why images are taking vastly more memory than I am expecting them to be, and am wondering if the issue is with something I'm missing with glide.我正在调试为什么图像占用的 memory 比我预期的要多得多,并且想知道问题是否与我在滑翔时缺少的东西有关。

    glide.asBitmap()
            .load(imageUrl)
            .apply(RequestOptions.centerCropTransform())
            .into(object : BitmapImageViewTarget(objectContainer) {
                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                    super.onResourceReady(resource, transition)
                    adapter.setPhoto(resource)

                    var numberOfBytes = resource.byteCount;

So the imageUrl if I download the image manually, is just 60126 bytes or 60 KB.因此,如果我手动下载图像,则 imageUrl 仅为 60126 字节或 60 KB。

When I print number of bytes after going through this glide load, my image is a whopping 7.6 MB.!!!当我在经历这个滑行加载后打印字节数时,我的图像高达 7.6 MB。!!! Its growing by a factor of 100+.它增长了 100+ 倍。

I've noticed that the sizes of any of the images are the same, so I'm wondering if there is some default bitmap buffer size that is massive, that is causing this issue.我注意到任何图像的大小都是相同的,所以我想知道是否有一些默认的 bitmap 缓冲区大小很大,这会导致这个问题。

When you save an image file on your disk it's usually compressed (JPEG, PNG, and...) so they usually have small size on your disk.当您将图像文件保存在磁盘上时,它通常是经过压缩的(JPEG、PNG 和...),因此它们在您的磁盘上通常很小。

But when that images go into memory (what glide does when it loads that images file) it goes all crazy and consumes all memory it needs because it's not compressed anymore, its RAW image that your working within your memory. But when that images go into memory (what glide does when it loads that images file) it goes all crazy and consumes all memory it needs because it's not compressed anymore, its RAW image that your working within your memory.

So a lossless compression format like JPEG can make the file size 500kb but when you load that image it can go for example to 10 MB on device memory.因此,像 JPEG 这样的无损压缩格式可以使文件大小为 500kb,但是当您加载该图像时,它可以 go 例如在设备 memory 上达到 10 MB。

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

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