Low quality image android development

I made a photoshop image 480x2500 which I want to put in one of my activities. But, after installing the .apk, the image has low quality. I really tried everything I found on google, without results. I'm not an experienced programmer so please take you time and explain everything that can help me. Here are my codes:

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 Code

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;
    }

    }

I tried to erase a tiny part of my image(to have a transparent background) but without results. Thank you.

Upvotes: 1

Views: 2892

Answers (3)

Farooq
Farooq

Reputation: 426

This code worked for me

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);

Upvotes: 0

lucignolo
lucignolo

Reputation: 221

How do you save the image from photoshop? Transparent png! With export for web

Upvotes: 1

Victor KP
Victor KP

Reputation: 437

Make sure the image is saved as a .png

Also, you probably want to run it through the Android Asset Studio, which will automatically scale the image for different screen densities.

Android Asset Studio

Upvotes: 1

Related Questions