Zhen
Zhen

Reputation: 12431

How to improve resolution of image on Android

I have uploaded an image which is on 3000 by 3000 pixel onto Android Studios.

When I try to add the image to my application, the image does not look sharp.

enter image description here

Here is my XML code

 <ImageView
   android:layout_width="match_parent"
   android:layout_height="200dip"
   android:scaleType="fitCenter"
   android:contentDescription=""
   android:layout_marginTop="20dip"
   android:layout_marginBottom="28dip"
   android:src="@mipmap/login_logo" />

I believe that my image should be big enough for the image view. Can anyone advise me on how to increase the resolution of my image?

Updated

When I uploaded the image, the 4 different versions of the image were created automatically in the system

enter image description here

Upvotes: 1

Views: 3914

Answers (2)

adalpari
adalpari

Reputation: 3121

The problem is that you are creating an icon set, wich actually does not have 3000 by 3000 pixel. Check it.

The application is using the more appropiate size (hdpi, xhdpi, etc). But you are resizing manually. That's why the icon is not sharp in the screen.

When you create a manual Image Asset, this is the real size depending on screen size. The assistan takes the original image and resizze it.

ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi

In pixels:

36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
144x144 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density

You can solve it, creating your custom image asset following this instructions:

LDPI - 0.75x
MDPI - Original size you want to show
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x

https://developer.android.com/guide/practices/screens_support.html

Or you can use an external library, like Picasso, to load the original image and fit it. The result will be more professional as far as you can dynamically fit, use placeholders, errorimage, etc.

https://www.google.es/?ion=1&espv=2#q=picasso%20android

Picasso.with(getActivity())
    .load(new File("path-to-file/file.png"))
    .into(imageView);

Upvotes: 2

Jame
Jame

Reputation: 3854

I suggest a method which use in onCreate() function. It used BitmapFactory to load your image

Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
ImageView mImg;
mImg = (ImageView) findViewById(R.id.imageView);
mImg.setImageBitmap(source);

Upvotes: 1

Related Questions