jasonpolites / gesture-imageview

Implements pinch-zoom, rotate, pan as an ImageView for Android 2.1+
1.15k stars 501 forks source link

CENTER_INSIDE and CENTER_CROP are completely off #24

Open goncalossilva opened 12 years ago

goncalossilva commented 12 years ago

The documentation states:

I've highlighted the important parts.

Basically, CENTER_CROP is scaling images it shouldn't scale (where both dimensions are already larger than the ImageView) and CENTER_INSIDE is not scaling properly, since a large image can always be dragged in one dimension.

httpdispatch commented 11 years ago

@goncalossilva did you find any fix for the CENTER_INSIDE issue?

httpdispatch commented 11 years ago

I've found a fix for initial state. Need to find same for pinch to unzoom

protected void computeStartingScale(int imageWidth, int imageHeight, int measuredWidth, int measuredHeight) {
        switch(getScaleType()) {
            case CENTER: 
                // Center the image in the view, but perform no scaling. 
                startingScale = 1.0f;
                break;

            case CENTER_CROP: 
                startingScale = Math.max((float) measuredHeight / (float) imageHeight, (float) measuredWidth/ (float) imageWidth);
                break;

            case CENTER_INSIDE: 
                // FIX center inside should not crop the image
                startingScale = Math.min(fitScaleHorizontal, fitScaleVertical);
                break;
        }
    }
goncalossilva commented 11 years ago

I forked this a while back. It's now too different from the original (this), but have a look: https://github.com/heavyplayer/gesture-imageview