Search code examples
androiduniversal-image-loader

Android Universal Image Loader onProgressUpdate total value always 512000


I'm using UIL, and I have a problem with image size which is always 512000 bytes!

here is my configuration:

Options decodingOptions = new Options();
        decodingOptions.inSampleSize = 1;
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
        .cacheInMemory(false)
        .decodingOptions(decodingOptions)
        .cacheOnDisk(true)
        .considerExifParams(true)
        .resetViewBeforeLoading(true)
        .imageScaleType(ImageScaleType.NONE)
        .bitmapConfig(Bitmap.Config.RGB_565)
        .build();

        ImageLoaderConfiguration config;
        config = new ImageLoaderConfiguration.Builder(getApplicationContext())
        .defaultDisplayImageOptions(defaultOptions)
        .denyCacheImageMultipleSizesInMemory()
        .build();

        ImageLoader.getInstance().init(config);

And I'm using it like this:

ImageLoader.getInstance().loadImage(imgUrl, null, null, new ImageLoadingListener() {

            @Override
            public void onLoadingStarted(String imageUri, View view) {

                    PB.setVisibility(View.VISIBLE);
                    PBText.setVisibility(View.VISIBLE);


            }

            @Override
            public void onLoadingFailed(String imageUri, View view,
                    FailReason failReason) {

                    PB.setVisibility(View.GONE);
                    PBText.setVisibility(View.GONE);


                switch (failReason.getType()) {
                case IO_ERROR:
                    message = mResources.getString(R.string.ioError);
                    break;
                case OUT_OF_MEMORY:
                    message = mResources.getString(R.string.outOfMemory);
                    break;
                case NETWORK_DENIED:
                    message = mResources.getString(R.string.networkDenied);
                    break;
                case UNKNOWN:
                    message = mResources.getString(R.string.unknownError);
                    break;
                case DECODING_ERROR:
                    message = mResources.getString(R.string.decodeError);
                    break;
                }


            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    PB.setVisibility(View.GONE);
                    PBText.setVisibility(View.GONE);
                    fullScreenImage.setImageBitmap(loadedImage);

                }



            }


        }, new ImageLoadingProgressListener() {

            @Override
            public void onProgressUpdate(String imageUri, View view, int current,
                    int total) {
                //here the value of total is always 512000!

                if((total != 0)&&(current != 0)){
                    PB.setProgress(Math.round(100.0f * current / total));                   
                }
                PBText.setText((current/1024)+" KB / "+(total/1024)+" KB"); 

            }
        });

And I'm sending the image from php:

header( 'Content-Type: image/jpg' );
readfile( $image_file );

it was working fine before, but now it's not. I don't know why. I'm using the latest jar of Universal Image Loader.

EDIT1: value of the current in onProgressUpdate is correct and it reaches the final size of the file.


Solution

  • That's because size of the content in the header is empty. The server should put Content-Length in the header. For example in php you should do it manually like this:

    <?php
        $file = "image.jpg"
        $size = filesize($file);
        header("Content-Type: image/jpeg");
        header("Content-length: $size");
        readfile($file);
    ?>