当Android N显示尺寸设置大于小时,“画布:尝试绘制太大的位图”

时间:2022-12-03 15:27:32

I have a published app that is crashing at startup on Android N when the newly introduced Display size OS setting is set to too large a value.

当新引入的显示大小操作系统设置设置为太大时,我有一个已发布的应用程序在Android N启动时崩溃。

When I look in logcat, I see the following message:

当我查看logcat时,我看到以下消息:

java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bitmap.

I've traced the issue to an ImageView in my first Activity that shows a nice big background image. The image in question is 2048x1066 and is in my generic drawables directory, so no matter the density, this image will be used.

我在第一个Activity中将问题跟踪到ImageView,它显示了一个漂亮的大背景图像。有问题的图像是2048x1066,位于我的通用drawables目录中,因此无论密度如何,都将使用此图像。

Everything works okay when the Display size setting is Small. But when I go up to Default, it stops working. If I then swap the image out with a smaller one, it works at Default, but if I go up to Large, it stops working again.

当“显示尺寸”设置为“小”时,一切正常。但是当我进入Default时,它会停止工作。如果我然后用较小的图像交换图像,它在默认情况下工作,但如果我上升到大,它会再次停止工作。

My guess is that adjusting Display size up causes your device to behave like a physically smaller device with a higher pixel density. But I don't understand what I'm supposed to do here. If I put in progressively smaller images for progressively higher resolutions, it won't look good on actually large displays. Or am I not understanding something?

我的猜测是,调整显示器尺寸会使您的设备表现得像具有更高像素密度的物理上更小的设备。但我不明白我应该在这做什么。如果我为逐渐提高的分辨率逐渐放入较小的图像,那么在实际大型显示器上看起来效果不佳。或者我不明白什么?

Any pointers would be greatly appreciated.

任何指针都将非常感激。

5 个解决方案

#1


83  

I my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.

我的情况下,将(高分辨率)飞溅位图从drawable移动到drawable-xxhdpi是解决方案。

I had the same problem. I didn't suspect my splash screen to be the problem, since it is displayed when the app is started, but it turned out the splash screen is the problem.

我有同样的问题。我没有怀疑我的启动画面是问题,因为它在应用程序启动时显示,但事实证明启动画面是问题所在。

The splash screen in my case has xxhdpi resolution, and it was mistakenly placed in the drawable folder, instead of drawable-xxhdpi. This made Android assume the splash screen had mdpi resolution and scale the image to 3*3 times it's required size and trying to create a bitmap.

我的情况下的启动画面有xxhdpi分辨率,它被错误地放在drawable文件夹中,而不是drawable-xxhdpi。这使Android假设启动画面具有mdpi分辨率并将图像缩放到所需大小的3 * 3倍并尝试创建位图。

#2


7  

I dont know would it help some one, but I'll just leave it here. In my case - problem was only on Sumsung devices with Android 7, and problem was in splash screen proportions. after changing height to 1024 px - everything waork fine

我不知道它会帮助一些人,但我会把它留在这里。在我的情况下 - 问题仅出现在使用Android 7的Sumsung设备上,并且问题在于闪屏比例。将高度改为1024 px后 - 一切都很好

#3


5  

Move your image in the drawable to mipmap-xxhdpi.Your image is in bitmap format so you should put your image in mipmap folder,then it will work

将您的图像在drawable中移动到mipmap-xxhdpi。您的图像是位图格式,因此您应该将图像放在mipmap文件夹中,然后它将工作

#4


3  

Try to use Bitmap.Factory class, this link will help you Loading Large Bitmaps Efficiently

尝试使用Bitmap.Factory类,此链接将帮助您有效地加载大位图

#5


0  

The icon files are too large for Android to efficiently and smoothly load. Android recognizes this with its smart algorithms.

图标文件太大,Android无法高效,流畅地加载。 Android通过其智能算法识别这一点。

You can resize the icon files using Final Android Resizer by asystat. Resize them to "xhdpi" or lower.

您可以使用asystat使用Final Android Resizer调整图标文件的大小。将它们调整为“xhdpi”或更低。

Place the resized photos in drawable or overwrite over the existing large icon files.

将调整大小的照片放在可绘制或覆盖现有的大图标文件上。

Then, you're done.

然后,你完成了。

#1


83  

I my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.

我的情况下,将(高分辨率)飞溅位图从drawable移动到drawable-xxhdpi是解决方案。

I had the same problem. I didn't suspect my splash screen to be the problem, since it is displayed when the app is started, but it turned out the splash screen is the problem.

我有同样的问题。我没有怀疑我的启动画面是问题,因为它在应用程序启动时显示,但事实证明启动画面是问题所在。

The splash screen in my case has xxhdpi resolution, and it was mistakenly placed in the drawable folder, instead of drawable-xxhdpi. This made Android assume the splash screen had mdpi resolution and scale the image to 3*3 times it's required size and trying to create a bitmap.

我的情况下的启动画面有xxhdpi分辨率,它被错误地放在drawable文件夹中,而不是drawable-xxhdpi。这使Android假设启动画面具有mdpi分辨率并将图像缩放到所需大小的3 * 3倍并尝试创建位图。

#2


7  

I dont know would it help some one, but I'll just leave it here. In my case - problem was only on Sumsung devices with Android 7, and problem was in splash screen proportions. after changing height to 1024 px - everything waork fine

我不知道它会帮助一些人,但我会把它留在这里。在我的情况下 - 问题仅出现在使用Android 7的Sumsung设备上,并且问题在于闪屏比例。将高度改为1024 px后 - 一切都很好

#3


5  

Move your image in the drawable to mipmap-xxhdpi.Your image is in bitmap format so you should put your image in mipmap folder,then it will work

将您的图像在drawable中移动到mipmap-xxhdpi。您的图像是位图格式,因此您应该将图像放在mipmap文件夹中,然后它将工作

#4


3  

Try to use Bitmap.Factory class, this link will help you Loading Large Bitmaps Efficiently

尝试使用Bitmap.Factory类,此链接将帮助您有效地加载大位图

#5


0  

The icon files are too large for Android to efficiently and smoothly load. Android recognizes this with its smart algorithms.

图标文件太大,Android无法高效,流畅地加载。 Android通过其智能算法识别这一点。

You can resize the icon files using Final Android Resizer by asystat. Resize them to "xhdpi" or lower.

您可以使用asystat使用Final Android Resizer调整图标文件的大小。将它们调整为“xhdpi”或更低。

Place the resized photos in drawable or overwrite over the existing large icon files.

将调整大小的照片放在可绘制或覆盖现有的大图标文件上。

Then, you're done.

然后,你完成了。