SimpleCropView icon indicating copy to clipboard operation
SimpleCropView copied to clipboard

i tried to crop an image but it always crops the middle and not the part i target

Open omryros opened this issue 9 years ago • 4 comments
trafficstars

like the title says , i use the crop tool and it always crops the middle part of the frame regardless of position

omryros avatar Mar 29 '16 16:03 omryros

me too.

xiang-xx avatar Aug 08 '16 07:08 xiang-xx

i got it. before startcrop, **do not do anything that can tigger CropImageView.onLayout。**such as show some view that hided。。。 bcz :

@Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (getDrawable() != null) setupLayout(mViewWidth, mViewHeight);
    }

private void setupLayout(int viewW, int viewH) {
        if (viewW == 0 || viewH == 0) return;
        setCenter(new PointF(getPaddingLeft() + viewW * 0.5f, getPaddingTop() + viewH * 0.5f));
        setScale(calcScale(viewW, viewH, mAngle));
        setMatrix();
        mImageRect = calcImageRect(new RectF(0f, 0f, mImgWidth, mImgHeight), mMatrix);
        mFrameRect = calcFrameRect(mImageRect);  // will init mFrameRect as initial,not where u dragged
        mIsInitialized = true;
        invalidate();
    }

remove the code that can tigger CropImageView.onLayout, and fixed。

by the way, i think this may be helpful: ···java @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (getDrawable() != null && !mIsInitialized ) setupLayout(mViewWidth, mViewHeight); } ···

or u can extend and rewrite the method。。。。 will help

xiang-xx avatar Aug 08 '16 07:08 xiang-xx

FixedCropImageView(will not work well when rotate....):

public class FixedCropImageView extends CropImageView {
    private boolean inited = false;
    public FixedCropImageView(Context context) {
        super(context);
    }

    public FixedCropImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FixedCropImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (!inited) {
            super.onLayout(changed, l, t, r, b);
        }
        inited = true;
    }
}

xiang-xx avatar Aug 08 '16 08:08 xiang-xx

Thanks a lot.

DasAyush avatar Aug 09 '19 10:08 DasAyush