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

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

问题描述

我有一个发布的应用程序,当新引入的Display size OS设置设置为一个太大的值时,在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,该View显示了一个不错的大背景图像.有问题的图像为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天全站免登陆