“画布:试图绘制太大的位图"当 Android N Display Size 设置为大于 Small [英] "Canvas: trying to draw too large bitmap" when Android N Display Size set larger than Small

查看:14
本文介绍了“画布:试图绘制太大的位图"当 Android N Display Size 设置为大于 Small的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当新引入的 Display size 操作系统设置设置为太大的值时,我有一个已发布的应用在 Android N 上启动时崩溃.

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.

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

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

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

我已将问题追溯到我的第一个 Activity 中的 ImageView,它显示了一个漂亮的大背景图像.有问题的图像是 2048x1066 并且在我的通用 drawables 目录中,因此无论密度如何,都将使用该图像.

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.

Display size 设置为 Small 时,一切正常.但是当我转到 Default 时,它停止工作.如果我然后用较小的图像换出图像,它会在 Default 下工作,但是如果我转到 Large,它会再次停止工作.

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.

我的猜测是,向上调整 Display size 会使您的设备表现得像物理上更小的设备,但像素密度更高.但我不明白我应该在这里做什么.如果我放入越来越小的图像以获得越来越高的分辨率,它在实际大显示器上看起来不会很好.还是我不明白什么?

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?

任何指针将不胜感激.

推荐答案

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

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

我遇到了同样的问题.我不怀疑我的启动画面是问题所在,因为它在应用程序启动时显示,但结果是启动画面是问题所在.

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.

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

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.

这篇关于“画布:试图绘制太大的位图"当 Android N Display Size 设置为大于 Small的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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