SimpleCropView
SimpleCropView copied to clipboard
i tried to crop an image but it always crops the middle and not the part i target
like the title says , i use the crop tool and it always crops the middle part of the frame regardless of position
me too.
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
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;
}
}
Thanks a lot.