gesture-imageview icon indicating copy to clipboard operation
gesture-imageview copied to clipboard

CENTER_INSIDE and CENTER_CROP are completely off

Open goncalossilva opened this issue 12 years ago • 3 comments

The documentation states:

  • CENTER_CROP: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
  • CENTER_INSIDE: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).

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.

goncalossilva avatar Jun 06 '12 02:06 goncalossilva

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

httpdispatch avatar Oct 29 '12 07:10 httpdispatch

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;
        }
    }

httpdispatch avatar Oct 29 '12 07:10 httpdispatch

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

goncalossilva avatar Oct 29 '12 07:10 goncalossilva