4

I have a gallery which is using Android universal image loader. Problem is that the images are just partially shown, like half of the image, sometimes no image, but sometimes the image is shown whole.

DisplayImageOptions options = new DisplayImageOptions.Builder()
                                            .cacheInMemory()
                                            .build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                                            .defaultDisplayImageOptions(options)
                                            .threadPoolSize(1)
                                            .threadPriority(Thread.MIN_PRIORITY + 3)
                                            .denyCacheImageMultipleSizesInMemory()
                                            .memoryCacheSize(2 * 1024 * 1024)
                                            .enableLogging()
                                            .build();

imageLoader = ImageLoader.getInstance();
imageLoader.init(config); 
imageLoader.handleSlowNetwork(true);


subImage1 = (ImageView)findViewById(R.id.subImage1);
subImage2 = (ImageView)findViewById(R.id.subImage2);

imageLoader.displayImage( "http://path/to/image1.webp", subImage1);
imageLoader.displayImage( "http://path/to/image2.webp", subImage2);

LAYOUT

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context=".MyActivity" >



<ImageView
    android:id="@+id/subImage1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true" />

<ImageView
    android:id="@+id/subImage2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/subImage1"/>


</RelativeLayout>

PROBLEM EXAMPLE

enter image description here

What could be the problem?

Krivers
  • 1,986
  • 2
  • 22
  • 45

2 Answers2

1

I was having the same problem

I believe, the solution you are looking for, lies in this bit here

//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
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;
}

This is from Line 99 to line 108 here: https://github.com/thest1/LazyList/blob/master/src/com/fedorvlasov/lazylist/ImageLoader.java

I am linking this so that you can check the code from the source and compare with your code.

You will need to change this bit here: final int REQUIRED_SIZE=70. Note that this number needs to the power of 2. With the default of 70, you will get small images and when used in applications which need to display bigger pictures, they will look distorted. Play around with that till you are satisfied with the result.

I personally use the value of final int REQUIRED_SIZE=512 without any problems whatsoever.

This should do the trick for you.

Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
1

Finally I have made several tests and conclusion is that ImageView in Android v4.0 can't show webp properly. The only solution which I found is to show webp images in webView, which renders this file type properly e.g. like here.

Community
  • 1
  • 1
Krivers
  • 1,986
  • 2
  • 22
  • 45