Fresco:如何获取原始位图大小?

Fresco: How to get original bitmap size?

我正在使用 Fresco 加载图像,如何获得原始位图大小?

这是我目前一直在尝试的

ImageRequest request = ImageRequestBuilder
    .newBuilderWithSource(uri)
    .setImageDecodeOptions(ImageDecodeOptions.newBuilder()
    .setBackgroundColor(Color.GREEN)
    .build())
    .setPostprocessor(new BasePostprocessor() {

        @Override
        public void process(Bitmap bitmap) {
            super.process(bitmap);
            width = bitmap.getWidth();
            height = bitmap.getHeight();
        }

        @Override
        public void process(Bitmap destBitmap, Bitmap sourceBitmap) {
            super.process(destBitmap, sourceBitmap);
        }
    }).build();

但有些感觉我没有得到原始尺寸。

按照 documentation 中的说明使用 ControllerListener


    private void monitorImageSize(ImagePerfData imagePerfData, String coverPath) {
        if (imagePerfData == null) {
            return;
        }
        ImageInfo imageInfo = imagePerfData.getImageInfo();
        if (imageInfo == null) {
            return;
        }
        Log.e("xxx",
                "width = " + imageInfo.getWidth() + ", imageHeight = " + imageInfo.getHeight() +
                        ", url= " + coverPath);

        if (imageInfo.getWidth() > 600 || imageInfo.getHeight() > 600) {
            Log.e("xxx", "monitorImageSize url = " + coverPath);
            ToastUtils.showLong("image too big! url = " + coverPath);
        }
    }

DraweeController controller = Fresco.newDraweeControllerBuilder()
                        .setUri(coverPath)
                        .setAutoPlayAnimations(true)
                        .setPerfDataListener(new ImagePerfDataListener() {
                            @Override
                            public void onImageLoadStatusUpdated(ImagePerfData imagePerfData, int imageLoadStatus) {
                                monitorImageSize(imagePerfData, coverPath);
                            }

                            @Override
                            public void onImageVisibilityUpdated(ImagePerfData imagePerfData, int visibilityState) {
                                monitorImageSize(imagePerfData, coverPath);
                            }
                        })
                        .build();