Skip to content

Instantly share code, notes, and snippets.

@NoahZu
Created November 25, 2016 06:52
Show Gist options
  • Select an option

  • Save NoahZu/528a56ae3d3e392c069113d169f029e5 to your computer and use it in GitHub Desktop.

Select an option

Save NoahZu/528a56ae3d3e392c069113d169f029e5 to your computer and use it in GitHub Desktop.
Fresco根据url获取Bitmap
/**
* 根据url获取图片
*/
private void getShareBitmap() {
ImageRequest request = ImageRequest.fromUri(type == 3 ? shateImageUrl : getCover(mLiveBean));
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource dataSource = imagePipeline.fetchDecodedImage(request, context);
try {
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
if (bitmap == null) {
return;
}
mShareBitmap = bitmap;
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here
}
}, CallerThreadExecutor.getInstance());
} finally {
if (mShareBitmap == null) {
mShareBitmap = BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher);
}
if (dataSource != null) {
dataSource.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment