gpt4 book ai didi

android - Fresco - 来自 ControllerListener 的 onIntermediateImageSet 未被调用

转载 作者:行者123 更新时间:2023-11-29 00:53:32 30 4
gpt4 key购买 nike

我正在尝试逐步加载大尺寸 JPG。我看到了this documentation使用 Fresco,这正是我想要的:模糊延迟加载效果。我从 repo sample 中获取了他们的代码看起来像这样包装:

ImageFormatProgressiveJpegFragment.java

  private void setImageUri(Uri uri) {
mDebugOutput.setText("");
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
.setProgressiveRenderingEnabled(mProgressiveRenderingEnabled)
.build();
DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setRetainImageOnFailure(true)
.setPerfDataListener(mImagePerfDataListener)
.setControllerListener(
new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@javax.annotation.Nullable ImageInfo imageInfo,
@javax.annotation.Nullable Animatable animatable) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, true);
}
}

@Override
public void onIntermediateImageSet(
String id, @javax.annotation.Nullable ImageInfo imageInfo) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, false);
}
}

@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
mDebugOutput.append(
String.format(
Locale.getDefault(),
"onIntermediateImageFailed, %s\n",
throwable.getMessage()));
}
})
.build();
mSimpleDraweeView.setController(controller);
}

private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
mDebugOutput.append(
String.format(
Locale.getDefault(),
"%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
mDateFormat.format(new Date(System.currentTimeMillis())),
isFinalImage ? "final" : "intermediate",
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality(),
qualityInfo.getQuality()));
}

result是加载时图像信息的输出。

除了部分替换日志外,我的代码看起来是一样的:

MyFrescoActivity.java


private String IMAGE_URL = "https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73726/world.topo.bathy.200406.3x5400x2700.png";

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(IMAGE_URL))
.setProgressiveRenderingEnabled(true)
.build();

DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setRetainImageOnFailure(true)
.setPerfDataListener(this)
.setControllerListener(
new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable animatable) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, true);
}
}

@Override
public void onIntermediateImageSet(
String id, @Nullable ImageInfo imageInfo) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, false);
}
}

@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
Log.i("DraweeUpdate",
String.format(
Locale.getDefault(),
"onIntermediateImageFailed, %s\n",
throwable.getMessage()));
}
})
.build();
simpleDraweeView.setController(controller);
}

private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
Log.i("DraweeUpdate", String.format(
Locale.getDefault(),
"%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
"",
isFinalImage ? "final" : "intermediate",
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality(),
qualityInfo.getQuality()));
}

仍然,我没有在 onIntermediateImageSet 上收到响应。当图像完全加载时,此监听器上唯一被调用的是 onFinalImageSet。任何人都知道发生了什么事?

最佳答案

  1. 您确定您的图像管道配置已针对 Showcase 示例中所示的渐进式 Jpeg 进行设置吗?
  2. 如果您的图片来自缓存,则可以立即显示。
  3. 同样,如果您的网络速度太快,您将看不到进度。

您可以尝试将模拟器和网络类型设置为 GPRS 进行测试

关于android - Fresco - 来自 ControllerListener 的 onIntermediateImageSet 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184627/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com