显示的启动画面徽标质量不佳 [英] Splash Screen logo displayed is of poor quality

查看:74
本文介绍了显示的启动画面徽标质量不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有:

启动画面,显示应用程序的徽标

Splash Screen , which displays the logo of the Application

正在做什么:

What is working :

如果我在SplashScreenActivity的布局中设置了ImageView,则屏幕将显示得很好,并可以根据需要转到FirstActivity.

The screen is being displayed perfectly well and is going to FirstActivity as desired if I set a ImageView in a layout for the SplashScreenActivity .

什么不是:

What isn't :

但是,这不是正确的方法,因为当布局膨胀时,应用程序启动时会产生延迟.我使用了推荐的方法,如下所示:

However this isn't the correct approach as it produces a delay when the App starts as layout is being inflated . I have used the recommended approach as follows :

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/black" />
    <item
        android:gravity="center">
        <bitmap
            android:src="@drawable/logo"
            android:gravity="center"/>
    </item>
</layer-list>

styles.xml

<style name="Splash" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

AndroidManifest.xml

<application
    android:theme="@style/Splash">

  • 当我尝试从mipmap文件夹设置位图src时,它会生成一个很小的图像.

    • When i tried to set the bitmap src from mipmap folder it produced a tiny image .

      因为我也有徽标的SVG文件,所以我尝试使用Vector Asset来产生可绘制但位图的src需要一张图片,应用崩溃了.

      As I also had the SVG file of the logo I tried using Vector Asset to produce a drawable but bitmap src needs an image and the App crashed .

      然后我尝试使用ImageMagick,InkScape从SVG生成PNG和其他工具,以及推荐使用的工具,可提供高质量的图像.

      Then I tried to generate a PNG from SVG using ImageMagick , InkScape and other tools with their recommended options for high quality images .

      但是它仍然不如使用带有Vector Drawable的ImageView作为其源图像那么清晰,最后我现在再也想不出其他任何方法了.

      But it still isn't as sharp as using a ImageView with a Vector Drawable as its source and finally I can't think of any other way now .

      那么,如何才能获得与其他所有应用程序相同的图像质量?还有什么办法可以使位图使用SVG本身?

      So , how can I achieve the same quality of the image like all other Apps have ? Also is there any way I can make bitmap use the SVG itself ?

      推荐答案

      @hrk唱歌是正确的,甚至不必费力尝试正确显示位图.您将始终获得低分辨率图像.您能做的最好的事情就是即使在诸如vectr之类的页面上也可以在线创建一个vectordrawable.我所做的就是直接在xml中直接缩放vectordrawable,最后终于在我的启动画面中完美地工作了

      @hrk sing is right, dont even bother trying to display a bitmap correctly. you will always get low resolution images. the best you can do is really create a vectordrawable even online on a page such as vectr. what I did is silmply scale the vectordrawable directly in the xml and it finally worked perfectly for my splash screen

      <vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
      android:viewportWidth="640"
      android:viewportHeight="640"
      android:width="240dp"
      android:height="240dp">
      <path
          android:pathData="M320.96 55.9L477.14 345L161.67 345L320.96 55.9Z"
          android:strokeColor="#292929"
          android:strokeWidth="24" />
      </vector>
      

      在上面的代码中,我将在640x640画布上绘制的可绘制对象缩放为240x240.然后我像这样将其插入到初始屏幕可绘制中,效果很好:

      in the code above I am rescaling a drawable I drew on a 640x640 canvas to be 240x240. then i just put in in my splash screen drawable like so and it works great:

      <?xml version="1.0" encoding="utf-8"?>
      

      <!-- The background color, preferably the same as your normal theme -->
      <item>
          <shape>
              <size android:height="120dp" android:width="120dp"/>
              <solid android:color="@android:color/white"/>
          </shape>
      </item>
      
      <!-- Your product logo - 144dp color version of your app icon -->
      <item
          android:drawable="@drawable/logo_vect"
          android:gravity="center">
      
      </item>
      

      我的代码实际上只是在下图中绘制了三角形,但是在这里您看到了可以实现的目标.与使用位图时获得的像素化边缘相反,分辨率终于达到了极高的水平.

      my code is actually only drawing the triangle in the following picture but here you see what you can achieve with this. Resolution is finally great as opposed to the pixelated edges I was getting when using bitmap.

      这篇关于显示的启动画面徽标质量不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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