2015-10-05 7 views
6

का उपयोग कर यूरी से बिटमैप लाने का प्रयास करें, का उपयोग करके Fresco का उपयोग करते हुए व्यवहार को समझें। जब मैं अपना कोड डीबग करता हूं तो यह onNewResultImpl या onFailureImpl निष्पादित कर रहा है और जब मैं चलाता हूं तो एप्लिकेशन काम नहीं कर रहा है इसका मतलब है कि इसे onFailureImpl या onNewResultImpl (मुझे ऐप चलाने के दौरान Toast और Log का उपयोग करके जांच रहा है)। मैंने देखा है इस SO Question and take ref from it और भी from Fresco's doc.फ्रेस्को

@Override 
protected 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 ","after callback"); 
            Toast.makeText(CommentActivity.this,"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(); 
         } 
        } 
       } 
     } 
    } 
} 

नोट: मैं किसी भी ऐनिमेटेड gif छवि

+0

श्रेणी स्तर –

+0

को 'imageRequest, imagePipeline और डेटा स्रोत' घोषित @KaranMer कोई प्रभाव नहीं – kId

+0

आप नवीनतम पुस्तकालय फ़ाइलें और जार फ़ाइलों –

उत्तर

11

मैं try और finally ब्लॉक और और समापन को हटा दिया है से जेपीजी छवि नहीं से बिटमैप पाने के लिए कोशिश कर रहा हूँ DatasourceonNewResultImpl और onFailureImpl

कोड स्निपेट

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()); 
+0

के लिए डेमो बनाने का प्रयास करें आश्चर्य कीजिए कि आपको 'Bitmap.createBitmap (बिटमैप 'क्यों चाहिए) 'बस' bmp = bitmap' के बजाय? –

+0

यह पूरा कोड नहीं है मैं वहां बिटमैप स्केल कर रहा था और उसे बीएमपी सौंपा गया था – kId