Ofir Hadad
Ofir Hadad

Reputation: 1900

android: (bad)low image quality in layout background

I tried all the answers that i found in the Android section with out any success before i post this question...
for some reason the image quality in the device is poor and in Eclipse and in the virtual device is very good
look on the screenshot example: example http://img714.imageshack.us/img714/1358/84044294.jpg

what should i do? i try to make the image with 72dpi and 300 dpi, the PNG/JPG resolution is 1280x800 but nothing works...
Please help!!

This is my LiveNewsActivity.java maybe i'm doing something wrong?

package com.prog.livenews;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;


public class LiveNewsActivity extends Activity {
/** Called when the activity is first created. */

//############################
//######### VARS #############

Button login;
Button register;

//############################
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    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.bg, options);

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

    login = (Button) findViewById(R.id.main_login_button);
    register = (Button) findViewById(R.id.main_register_button);



    login.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.prog.livenews.LOGIN"));
        }
    });

    register.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.prog.livenews.REGISTER"));
        }
    });


}

}

Upvotes: 4

Views: 5225

Answers (4)

ademar111190
ademar111190

Reputation: 14505

try it:

put it before setContentView(layoutId) on your first activity

getWindow().setFormat(PixelFormat.RGBA_8888);

and after call setContentView(layoutId) in your first activity you put the bellow code:

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

and finnaly you put your xml images in res/drawable "if you have xml images" folder and the png, jpeg and others normals images you put in res/drawable-hdpi folder.

Hope this helps.

Upvotes: 7

Ofir Hadad
Ofir Hadad

Reputation: 1900

O.K guys, I found a solution... As i understand... when saving the gradient image in Photoshop, Photoshop will try to optimize the image size by removing the Alpha channel.

So you need to delete one pixel from the top (left/right) corner or the buttom (right/left) corner

and then Photoshop will "see" that the image have an Alpha channel and it will work on the Device... be aware... some devices are not able to show gradient color perfect..

Hope that was helpful! Thanks guys for your help!

Upvotes: 2

Pavandroid
Pavandroid

Reputation: 1586

Try using the High Quality Image. Can you confirm whether background is also containing the Globe Image and text on it? Is background is having gradient color or not ?

Upvotes: 0

kabuko
kabuko

Reputation: 36302

I tried all the answers that i found in the Android section with out any success

It'd be helpful if you stated which approaches you've tried too, but Marc's comment is correct. You need to make sure your image and window are both higher bit depth (probably ARGB_8888). See this article for more info and you can possibly enable dithering. Putting this in onCreate should take care of a lot:

getWindow().setFormat(PixelFormat.RGBA_8888);

Upvotes: 2

Related Questions