0

I was trying to use Fresco over Picasso to avoid memory leaks but found that Fresco does not support scaling as it is supported by Picasso

Following is my code to resize image using picasso

 PicassoCache.getPicassoInstance(holder.itemView.getContext()) 
.load(Uri.encode(item.imageUrl, Constants.ALLOWED_URI_CHARS)) 
.tag(Constants.IMAGE_LOADING_TAGS.ALL_DEAL) 
.placeholder(R.drawable.imgload)
.error(R.drawable.imgntfound) 
.resize(200, 0) 
.into(holder.itemImage);

Now here picasso allows either width and height to be zero and resize image accordingly. But found that Fresco does not support any functionality like this I had to specify both width and height.

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) 
.setResizeOptions(new ResizeOptions(200, 200)) 
.build(); 
DraweeController controller = Fresco.newDraweeControllerBuilder() 
.setOldController(holder.itemImage.getController())  
.setImageRequest(request) 
.build(); 
 holder.itemImage.setController(controller);

Is there any chance to achieve this using fresco

amodkanthe
  • 4,345
  • 6
  • 36
  • 77

2 Answers2

0

You can achieve like this it works for me.

ImageRequest request = ImageRequestBuilder
                .newBuilderWithSource(uri)
                .setResizeOptions(new ResizeOptions(250, 250))
                .setLocalThumbnailPreviewsEnabled(true).build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(holder.iv_product.getController())
                .build();
holder.iv_product.setController(controller);

Here is my layout.xml which I was used.

<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/iv_product"
        android:layout_width="160dp"
        android:layout_height="165dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_vertical|center_horizontal"
        android:padding="1dp"
        fresco:actualImageScaleType="fitCenter"
        fresco:fadeDuration="1000"
        fresco:placeholderImage="@drawable/default_product_logo"
        fresco:viewAspectRatio="0.99" />
Andy Developer
  • 3,071
  • 1
  • 19
  • 39
0

See my answer on GitHub: Unfortunately this is currently not supported you have to specify both the width and height. Similarly, Fresco also does not support wrap_content. More information on this topic can be found here: http://frescolib.org/docs/wrap-content.html

Alexander Oprisnik
  • 1,212
  • 9
  • 9
  • is there any chance Fresco library will support functionality like these. In my app there are lots of scenarios where I don't know height or width or aspect ratio. For now is it possible to get width and height of image then I will specify aspect ratio programmatically – amodkanthe May 04 '17 at 16:27