Android Universal Image Loader onProgressUpdate总值始终为512000

时间:2015-11-05 18:15:11

标签: android universal-image-loader

我正在使用UIL,我的图像大小有问题,总是512000字节!

这是我的配置:

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);

我正在使用它:

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"); 

            }
        });

我正在从php发送图像:

header( 'Content-Type: image/jpg' );
readfile( $image_file );
之前它工作正常,但现在不行。我不知道为什么。 我正在使用最新的Universal Image Loader。

EDIT1:onProgressUpdate中当前的值是正确的,它达到了文件的最终大小。

1 个答案:

答案 0 :(得分:0)

这是因为标题中内容的大小为空。 服务器应将Content-Length放在标头中。 例如在php中你应该像这样手动执行:

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