erdomester
erdomester

Reputation: 11829

Universal ImageLoader doesn't display full image

I am trying to show an image in an ImageView with Universal ImageLoader but only part of the image is shown. It's like it's zoomed in for some reason.

public class Image extends Activity {

    ImageView iv;
    protected ImageLoader imageLoader = ImageLoader.getInstance();
    DisplayImageOptions options;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image);

        iv = (ImageView) findViewById(R.id.imageView1);

        options = new DisplayImageOptions.Builder()
           .showImageForEmptyUri(R.drawable.noimage)
           .cacheOnDisc(true)
           .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
           .cacheInMemory(true)
           .bitmapConfig(Bitmap.Config.RGB_565)
           .displayer(new RoundedBitmapDisplayer(0))
           .build();

        if (!imageLoader.isInited()) {
            initImageLoader();
        }

        Intent intent = getIntent();
        String image = intent.getStringExtra("image");
        Log.i("Image", "" + image);
        if (image != null) {
            imageLoader.displayImage("https://www.example.com/"+image, iv, options);
        }

    }

    private void initImageLoader() {
        int memoryCacheSize;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
            int memClass = ((ActivityManager) 
                    this.getSystemService(Context.ACTIVITY_SERVICE))
                    .getMemoryClass();
            memoryCacheSize = (memClass / 8) * 1024 * 1024;
        } else {
            memoryCacheSize = 2 * 1024 * 1024;
        }

        final ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                this).threadPoolSize(5)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .memoryCacheSize(memoryCacheSize)
                //.memoryCache(new FIFOLimitedMemoryCache(memoryCacheSize-1000000))
                .denyCacheImageMultipleSizesInMemory()
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .build();

        ImageLoader.getInstance().init(config);
    }

}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#000000" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop" />

</LinearLayout>

That's the whole activity, no code was left out.

enter image description here

Upvotes: 0

Views: 1505

Answers (2)

erdomester
erdomester

Reputation: 11829

Some setting must be wrong with .displayer(new RoundedBitmapDisplayer(0)) because it is what caused the error. Setting the round value to 0 was not enough, I had to remove this line in order to display the image in the correct form.

Upvotes: 2

Giru Bhai
Giru Bhai

Reputation: 14398

To fit image in ImageView,Change

 .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)

to

.imageScaleType(ImageScaleType.EXACTLY) 

And in your xml layout

change

   android:scaleType="centerCrop"

to

    android:scaleType="fitCenter"

Upvotes: 0

Related Questions