Java教程

Flutter 设置安卓启动页报错 java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bi

本文主要是介绍Flutter 设置安卓启动页报错 java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bi,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

设置安卓启动页报错

  • 首先设置安卓启动页

  • 在android/app/src/main/AndroidManifest.xml中添加这一行

image

  • 然后找到android/app/src/main/res/drawable/launch_background.xml
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />
  • 添加代码
<!-- You can insert your own image assets here -->
     <item>
    <!-- android:gravity="center" -->
        <bitmap
         android:src="@drawable/splash"/>
    </item> 
  • 如果在这里不行就将代码放在同级的另一个drawable-v21文件夹中,然后将图片放在drawable文件夹中

  • 结果运行之后发现报错图片太大,在网上压缩图片从2.9MB到400K都还是报错,最后在stackflow上找到解决办法

https://stackoverflow.com/questions/39111248/canvas-trying-to-draw-too-large-bitmap-when-android-n-display-size-set-larger/44072270#44072270?newreg=b5b40430a64f4ad9b56afac076c58228

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

image

  • 将图片从drawable中移动到mipmap-xxxhdpi中

  • 然后更改drawable或者drawable-21文件夹中launch_background.xml的代码为新的地址

<item>
    <bitmap android:src="@mipmap/splash" />
</item>
  • 就好啦
这篇关于Flutter 设置安卓启动页报错 java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bi的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!