fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Is there a way to make PhotoView work with Fresco?

Open shen0834 opened this issue 11 years ago • 9 comments

https://github.com/chrisbanes/PhotoView/blob/master/library/src/main/java/uk/co/senab/photoview/PhotoView.java

i'm trying to use fresco replace the imageloder , i'm trying to let PhotoView extends SimpleDraweeView , override the method onDraw and onTouchEvent,but PhotoView It doesn't work

Is there a way to make PhotoView work with Fresco? Thanks!

shen0834 avatar Apr 22 '15 06:04 shen0834

The most likely reason why it doesn't work is because the drawable used by Drawee doesn't expose its intrinsic dimensions (i.e. it always returns -1). Because of that PhotoViewAttacher cannot determine the size of the image. The reason why Drawee top-level-drawable doesn't expose its intrinsic dimensions is because intrinsic dimensions change when the image loads. In particular, first the placeholder drawable is displayed and therefore the intrinsic dimensions should be that of the placeholder drawable. Then once the actual image loads, for a brief period of time, during the fade animatiom, both placeholder and the actual image are visible. It is not clear what intrinsic dimensions should be reported at that time (perhaps max of the two?). Finally, once the fade animation is over, the intrinsic dimensions should be that of the actual image. Drawee knows how to handle those changes gracefully, but we cannot assume the same for the containing image view. Therefore, we decided not to return intrinsic dimensions and to handle scaling internally instead.

I don't think PhotoView / PhotoViewAttacher can easily be made work with Fresco because PhotoViewAttacher relies on ImageView and Drawee doesn't support ImageView attributes. For example, PhotoViewAttacher sets MATRIX scale type and then tries to set the matrix to the ImageView.

There is however a way to make Drawee work with some zoomble logic. First, you need to specify a controller listener while building the controller, so that you can intercept the load events (onFinalImageSet for example). See http://frescolib.org/docs/listening-download-events.html#_ Then, when the image gets loaded, you can enable your zoomable logic and inform it about the image dimensions. To get the bounds of the image in the view, see GenericDraweeHierarchy.getActualImageBounds.

plamenko avatar Apr 23 '15 23:04 plamenko

thinks your help!

https://github.com/shen0834/wangyue-learngit/blob/master/SimplePhotoView.java

I made a simple implementation, if some one also have the same problem, you can refer to

shen0834 avatar Apr 24 '15 07:04 shen0834

@shen0834, thanks!

Could you make the behaviour like this: https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java

chongivan avatar Apr 27 '15 02:04 chongivan

i will add description provided 6 hours later ,now it's working time

shen0834 avatar Apr 27 '15 03:04 shen0834

@shen0834 have a nice day =)

chongivan avatar Apr 27 '15 03:04 chongivan

It seems Fresco now supports pinch-to-zoom feature, with ZoomableDraweeView. See commit 4e516e7 for the details, and those who are interested to its usage, see ZoomableDraweeView-sample on GitHub.

kunny avatar Jun 16 '15 16:06 kunny

Hey guys. If anyone still interested in how to use PhotoViewAttacher with Fresco here is my solution.

public class PhotoViewDraweeAttacher extends PhotoViewAttacher<SimpleDraweeView> {

    private RectF displayRect;

    public PhotoViewDraweeAttacher(SimpleDraweeView imageView) {
        super(imageView);
    }

    public RectF getActualImageBounds() {
        try {
            if(displayRect==null) {
                displayRect = new RectF();
            }
            getImageView().getHierarchy().getActualImageBounds(displayRect);
        } catch (Exception e) {
        }
        return displayRect;
    }

    @Override
    protected int getImageViewWidth(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.width());
        }
        return super.getImageViewWidth(imageView);
    }

    @Override
    protected int getImageViewHeight(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.height());
        }
        return super.getImageViewHeight(imageView);
    }

    @Override
    protected int getIntrinsicWidth(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.width());
        }
        return super.getIntrinsicWidth(imageView);
    }

    @Override
    protected int getIntrinsicHeight(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.height());
        }
        return super.getIntrinsicHeight(imageView);
    }
}

ffelini avatar Sep 28 '15 14:09 ffelini

If anyone still interested in PhotoView version that works with Fresco here is my fork https://github.com/namshi/PhotoView/tree/fresco_refactoring

Rotation feature not working properly yet.

ffelini avatar Oct 06 '15 13:10 ffelini

Hey @ffelini, thanks for your fork. It works well, but the picture does not stay centered while zooming. I did not investigate it further, but i found another working solution, which does the job. See here: https://github.com/06peng/FrescoDemo/tree/master/app/src/main/java/uk/co/senab/photoview.

bastiamponsah avatar Oct 09 '15 20:10 bastiamponsah