Android: (poor) poor image quality in layout

I tried all the answers that I found in the Android section, without any success, before posting this question ...
for some reason, the image quality in the device is poor, but in Eclipse and the virtual device is very good - see an example screenshot: example http://img714.imageshack.us/img714/1358/84044294.jpg

what should I do? I'm trying to make an image with a resolution of 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")); } }); } } 
+4
source share
4 answers

OK guys, I found a solution ... As I understand it ... when saving a gradient image in Photoshop, Photoshop will try to optimize the image size by removing the alpha channel.

So, you need to remove one pixel from the top (left / right) corner or in the corner (right / left)

and then Photoshop will see that the image has an alpha channel and it will work on the device ... keep in mind ... some devices cannot show the perfect gradient color.

Hope this was helpful! Thanks guys for your help!

+2
source

try:

put it before setContentView (layoutId) in your first activity.

 getWindow().setFormat(PixelFormat.RGBA_8888); 

and after calling setContentView (layoutId) in your first action, you added the following 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", as well as png, jpeg and other normal images that you put in the res / drawable-hdpi folder.

Hope this helps.

+7
source

I tried all the answers that I found in the Android section without any success.

It would be helpful if you stated what approaches you tried too, but Marc's comment is correct. You must make sure that your image and window have a higher bit depth (possibly ARGB_8888). See this article for more details and you can enable anti-aliasing. Putting this in onCreate to take care of a lot:

 getWindow().setFormat(PixelFormat.RGBA_8888); 
+2
source

Try using a high quality image. Can you confirm if the background also contains a globe image and text on it? Does the background have a gradient color or not?

+1
source

Source: https://habr.com/ru/post/1402501/


All Articles