【问题标题】:Low quality image android development低质量图像android开发
【发布时间】:2012-12-12 23:59:00
【问题描述】:

我制作了一张 480x2500 的 Photoshop 图片,我想将其放入我的一项活动中。 但是,安装 .apk 后,图像质量很差。我真的尝试了我在谷歌上找到的所有东西,但没有结果。我不是一个经验丰富的程序员,所以请花点时间解释一切可以帮助我的事情。 这是我的代码:

XML:

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:tileMode="repeat"
android:dither="true">

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="fill_parent"
    android:layout_height="1166dp"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/secondbutton3" />

Java 代码

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.WindowManager;

public class Secondbutton extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_secondbutton);
        getWindow().setFormat(PixelFormat.RGBA_8888);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.secondbutton, options);

        findViewById(R.id.imageView2).setBackgroundDrawable(new BitmapDrawable(gradient));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_secondbutton, menu);
        return true;
    }

    }

我尝试擦除图像的一小部分(以获得透明背景)但没有结果。 谢谢。

【问题讨论】:

  • 那行是错误的android:layout_height="1166dp"
  • 我通过makeappicon.com 解决了因为android studio 使图像质量低于预期不知道为什么

标签: java android bitmap png


【解决方案1】:

确保图像保存为 .png

此外,您可能希望通过 Android Asset Studio 运行它,它会自动缩放图像以适应不同的屏幕密度。

Android Asset Studio

【讨论】:

  • 我使用了 Asset Studio,但屏幕上显示的图像比例更差。
【解决方案2】:

如何从 Photoshop 中保存图像? 透明PNG! 带网页导出

【讨论】:

  • 我使用 Save for Web and Devices 选项卡将其保存为 .png。
【解决方案3】:

这段代码对我有用

BitmapFactory.Options myOptions = new BitmapFactory.Options();
    myOptions.inDither = true;
    myOptions.inScaled = false;
    myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
    myOptions.inDither = false;
    myOptions.inPurgeable = true;
    Bitmap preparedBitmap = BitmapFactory.decodeResource(yourAppName.getSharedApplication().getResources(),
            R.drawable.yourImage, myOptions);
    Drawable background = new BitmapDrawable(preparedBitmap);
    ((LinearLayout) findViewById(R.id.yourLayoutId))
        .setBackgroundDrawable(background);

【讨论】:

    猜你喜欢
    • 2016-02-09
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    • 2014-10-14
    相关资源
    最近更新 更多