Fresco's
doc. @OverrIDeprotected voID onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode,resultCode,data); if (resultCode == Activity.RESulT_OK) { switch (requestCode) { case ACTION_OPEN_galLERY: mImageCaptureUri = data.getData(); if (mImageCaptureUri != null) { commentimgVIEw.setimageURI(mImageCaptureUri);//mImageCaptureUri is working fine try { imageRequest = ImageRequestBuilder .newBuilderWithSource(mImageCaptureUri) .setRequestPriority(Priority.HIGH) .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FulL_FETCH) .build(); dataSource = imagePipeline.fetchDecodedImage(imageRequest,CommentActivity.this); dataSource.subscribe(new BaseBitmapDataSubscriber() { @OverrIDe protected voID onNewResultImpl(@Nullable Bitmap bitmap) { if (bitmap != null) { bmp = Bitmap.createBitmap(bitmap); Log.d("Bitmap ","after callback"); Toast.makeText(CommentActivity.this,"has bitmap",Toast.LENGTH_SHORT).show(); } else { Log.d("Bitmap is null ","bitmap is null",Toast.LENGTH_SHORT).show(); } } @OverrIDe protected voID onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) { Log.d("Bitmap ","after callback failure"); Toast.makeText(CommentActivity.this,"Failure",Toast.LENGTH_SHORT).show(); } },CallerThreadExecutor.getInstance()); } catch (Exception e){ e.printstacktrace(); } finally { if (dataSource != null) { dataSource.close(); } } } } }}
注意:我试图从jpg图像获取位图,而不是从任何动画gif图像
解决方法 我已经删除了try并最终阻止并关闭了onNewResultImpl和onFailureImpl中的Datasource代码段
ImageRequest imageRequest = ImageRequestBuilder .newBuilderWithSource(mImageCaptureUri) .setautoRotateEnabled(true) .build();ImagePipeline imagePipeline = Fresco.getimagePipeline();final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest,this);dataSource.subscribe(new BaseBitmapDataSubscriber() { @OverrIDe public voID onNewResultImpl(@Nullable Bitmap bitmap) { if (dataSource.isFinished() && bitmap != null){ Log.d("Bitmap","has come"); bmp = Bitmap.createBitmap(bitmap); dataSource.close(); } } @OverrIDe public voID onFailureImpl(DataSource dataSource) { if (dataSource != null) { dataSource.close(); } } },CallerThreadExecutor.getInstance());总结
以上是内存溢出为你收集整理的android – 尝试使用Fresco从uri获取位图全部内容,希望文章能够帮你解决android – 尝试使用Fresco从uri获取位图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)