Created
November 25, 2016 06:52
-
-
Save NoahZu/528a56ae3d3e392c069113d169f029e5 to your computer and use it in GitHub Desktop.
Fresco根据url获取Bitmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 根据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