Search code examples
androidbitmapandroid-imageviewandroid-fullscreen

displaying image full screen - loses quality android


I'm trying to display image full screen but seems that the image loses quality. I get the image from an URL, I download it and when I'm displaying the images, it looks pretty bad. The images that I'm getting are in high resolution so I do not know what can the problem be?

Here is my Layout where i'm displaying the image:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/full_screen_banner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name" />

and here is the java code:

imageViews.put(imageView, url);
Bitmap bitmap = memoryCache.get(url);
if (bitmap != null)
    imageView.setImageBitmap(bitmap);

Solution

  • If you are using image loader just go to imageloader class then

    Check these lines

        private Bitmap decodeFile(File f) {
        try {
            // decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f), null, o);
            // Find the correct scale value. It should be the power of 2.
            final int REQUIRED_SIZE = 100;
            int width_tmp = o.outWidth, height_tmp = o.outHeight;
            int scale = 1;
            while (true) {
                if (width_tmp / 2 < REQUIRED_SIZE
                        || height_tmp / 2 < REQUIRED_SIZE)
                    break;
                width_tmp /= 2;
                height_tmp /= 2;
                scale *= 2;
            }
            // decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {
        }
        return null;
    }