在Android的哪里存储图片 [英] Where to store images in Android

查看:147
本文介绍了在Android的哪里存储图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将所有图像从文件夹mipmap移到了drawable,因为在这里说mipmap文件夹仅用于应用程序图标来启动应用程序然后,我将同一文件移回了文件夹mipmap-xxxhdpi,现在看起来又不错了.所以我现在的问题是,将图像放在mipmap-xxxhdpi文件夹而不是drawable文件夹中还可以吗?我会为每一个建议感到高兴,因为我现在很困惑.

解决方案

java.lang.RuntimeException:画布:也试图绘制大(188394348bytes)位图

此异常主要是因为您试图显示一个高分辨率的大图像〜188MB,而android对此有所限制,这也报告了 1 Glide &毕加索提供磁盘,网络和&在ImageViews上显示图像时使用内存管理技术.

您可能会考虑的一种选择是在加载图像之前调整图像的大小,因此可以查看Mipmaps vs. drawable folders (the answer got 841 likes). However, when I now want to start my app I get an error message

 FATAL EXCEPTION: main
    Process: com.example.td.barapp, PID: 4331
    java.lang.RuntimeException: Canvas: trying to draw too large(188394348bytes) bitmap.
        at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)

In several realted questions people tell to store the pictures in different drawable folders (see Android : Understanding drawable folder) like drawable-xxhdpi or drawable-xxxhdpi.

Update: I was told by someone in this post (who later deleted his answers) to store the image (which has a size of 1,7 MB) in the folder drawable-anydpi. I did as he said but the outcome on the Emulator looks quite bad for an imageview (see screenshot): Then I moved the same file back into the folder mipmap-xxxhdpi and now it looks good again. So my question now is, whether it is also okay to have the image in the mipmap-xxxhdpi folder instead of the drawable folder? I'd be happy for every advice because I am quite confused now.

解决方案

java.lang.RuntimeException: Canvas: trying to draw too large(188394348bytes) bitmap

This exception mainly because you are trying to display a big image ~ 188MB which will have a high resolution, and android puts limitation on that, This also reported here.

One of the reasons is to save device resources; for instance you might get java.lang.OutOfMemory, so the system save device memory from that.

1, 2, 3 may guide you thoroughly on that.

Normally you can use a few mega bytes image in your app ~0-3MBs. Third party libraries like Glide & Picasso offer disk, network, & memory management techniques while displaying images on your ImageViews.

One of the options you may consider is to resize images before loading them, so can have look on this question.

Keep in mind that android puts limitaion on your apk file on the app store, so you need to minimize images for that reason, or load them from a back-end server.

As you mentioned, you can only put app icons in res\mipmap. And if you decide to put the images on your app, it's efficient to create them in different densities (hdpi, xhdpi, xxhdpi, xxxhdpi...), so they can match all the variety of device resolutions, and lets you avoid distorted images or high processing by android OS to match your image to the device resolution before displaying them.

这篇关于在Android的哪里存储图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆