फ्रेस्को के रूप में कहा: -:
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
// You can use the bitmap in only limited ways
// No need to do any cleanup.
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here.
}
},
executor);
आप कर सकते हैं
तो पाइप लाइन के लिए आपके अनुरोध एक डीकोड छवि के लिए है एक Android बिटमैप, आप हमारी आसान से उपयोग BaseBitmapDataSubscriber का लाभ ले सकते किसी भी चर के लिए बिटमैप असाइन न करें, NNResultImpl विधि के दायरे में नहीं।
http://frescolib.org/docs/datasources-datasubscribers.html#_
मेरे कोड:
public void setDataSubscriber(Context context, Uri uri, int width, int height){
DataSubscriber dataSubscriber = new BaseDataSubscriber<CloseableReference<CloseableBitmap>>() {
@Override
public void onNewResultImpl(
DataSource<CloseableReference<CloseableBitmap>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<CloseableBitmap> imageReference = dataSource.getResult();
if (imageReference != null) {
final CloseableReference<CloseableBitmap> closeableReference = imageReference.clone();
try {
CloseableBitmap closeableBitmap = closeableReference.get();
Bitmap bitmap = closeableBitmap.getUnderlyingBitmap();
if(bitmap != null && !bitmap.isRecycled()) {
//you can use bitmap here
}
} finally {
imageReference.close();
closeableReference.close();
}
}
}
@Override
public void onFailureImpl(DataSource dataSource) {
Throwable throwable = dataSource.getFailureCause();
// handle failure
}
};
getBitmap(context, uri, width, height, dataSubscriber);
}
/**
*
* @param context
* @param uri
* @param width
* @param height
* @param dataSubscriber
*/
public void getBitmap(Context context, Uri uri, int width, int height, DataSubscriber dataSubscriber){
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
if(width > 0 && height > 0){
builder.setResizeOptions(new ResizeOptions(width, height));
}
ImageRequest request = builder.build();
DataSource<CloseableReference<CloseableImage>>
dataSource = imagePipeline.fetchDecodedImage(request, context);
dataSource.subscribe(dataSubscriber, UiThreadExecutorService.getInstance());
}
AFAIK के बाद से फ्रेस्को मानक बिटमैप वर्ग पर बल्कि अपने खुद के कार्यान्वयन में निर्भर नहीं करता इस पुस्तकालयों स्वैप करने के लिए कोई सीधा तरीका नहीं है। –