|
@@ -98,8 +98,8 @@ public class CropView extends View {
|
|
|
// 图片放在不同的文件夹下,outHeight会不一样,放在dpi越高的文件夹,值越小
|
|
// 图片放在不同的文件夹下,outHeight会不一样,放在dpi越高的文件夹,值越小
|
|
|
minWidth = horizontalOptions.outHeight * 2;
|
|
minWidth = horizontalOptions.outHeight * 2;
|
|
|
minHeight = minWidth;
|
|
minHeight = minWidth;
|
|
|
- //doLayout(mViewWidth, mViewHeight);
|
|
|
|
|
- setScanArea(SCAN_TYPE_ALL); //height is ready
|
|
|
|
|
|
|
+ doLayout(mViewWidth, mViewHeight);
|
|
|
|
|
+ setScanArea(SCAN_TYPE_ALL);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
//post(() -> );
|
|
//post(() -> );
|
|
@@ -134,12 +134,12 @@ public class CropView extends View {
|
|
|
break;
|
|
break;
|
|
|
case SCAN_TYPE_ALL:
|
|
case SCAN_TYPE_ALL:
|
|
|
isLandscape = true;
|
|
isLandscape = true;
|
|
|
- coverHeight = getHeight();
|
|
|
|
|
|
|
+ coverHeight = getHeight() - getPaddingTop() - getPaddingBottom();
|
|
|
coverWidth = (int) (coverHeight/1.73);
|
|
coverWidth = (int) (coverHeight/1.73);
|
|
|
|
|
|
|
|
// 起始位置
|
|
// 起始位置
|
|
|
sX = (getWidth()*1.0f-coverWidth)/2;
|
|
sX = (getWidth()*1.0f-coverWidth)/2;
|
|
|
- sY = 0;
|
|
|
|
|
|
|
+ sY = getPaddingTop();
|
|
|
mFrameRectF = new RectF(sX, sY, sX + coverWidth, sY + coverHeight);
|
|
mFrameRectF = new RectF(sX, sY, sX + coverWidth, sY + coverHeight);
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
@@ -180,6 +180,13 @@ public class CropView extends View {
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
|
private void init() {
|
|
private void init() {
|
|
|
|
|
+ float handleLineLeftX = mFrameRectF.left - mHandleWidth;
|
|
|
|
|
+ float handleLineRightX = mFrameRectF.right + mHandleWidth;
|
|
|
|
|
+ float handleLineTopY = mFrameRectF.top - mHandleWidth;
|
|
|
|
|
+ float handleLineBottomY = mFrameRectF.bottom + mHandleWidth;
|
|
|
|
|
+ coverWidth = (int) (handleLineRightX - handleLineLeftX);
|
|
|
|
|
+ coverHeight = (int) (handleLineBottomY - handleLineTopY);
|
|
|
|
|
+
|
|
|
WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
|
WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
|
|
int width = manager.getDefaultDisplay().getWidth();
|
|
int width = manager.getDefaultDisplay().getWidth();
|
|
|
int height = manager.getDefaultDisplay().getHeight();
|
|
int height = manager.getDefaultDisplay().getHeight();
|
|
@@ -187,8 +194,8 @@ public class CropView extends View {
|
|
|
mBitmapCover = makeBitmap(width, height, getResources().getColor(R.color.black_transparent), 0, 0);
|
|
mBitmapCover = makeBitmap(width, height, getResources().getColor(R.color.black_transparent), 0, 0);
|
|
|
mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
|
|
mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
|
|
|
|
|
|
|
|
- eX = sX + coverWidth;
|
|
|
|
|
- eY = sY + coverHeight;
|
|
|
|
|
|
|
+ eX = mFrameRectF.right;
|
|
|
|
|
+ eY = mFrameRectF.bottom;
|
|
|
|
|
|
|
|
xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
|
|
xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
|
|
|
|
|
|
|
@@ -251,7 +258,7 @@ public class CropView extends View {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
- doLayout(mViewWidth, mViewHeight);
|
|
|
|
|
|
|
+ //doLayout(mViewWidth, mViewHeight);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -730,13 +737,27 @@ public class CropView extends View {
|
|
|
* @param canvas
|
|
* @param canvas
|
|
|
*/
|
|
*/
|
|
|
private void drawHandleLines(Canvas canvas) {
|
|
private void drawHandleLines(Canvas canvas) {
|
|
|
- mFramePaint.setColor(mHandleColor);
|
|
|
|
|
- mFramePaint.setStyle(Paint.Style.FILL);
|
|
|
|
|
// 指导线最边界(最左/最右/最下/最上)的x和y
|
|
// 指导线最边界(最左/最右/最下/最上)的x和y
|
|
|
float handleLineLeftX = mFrameRectF.left - mHandleWidth;
|
|
float handleLineLeftX = mFrameRectF.left - mHandleWidth;
|
|
|
float handleLineRightX = mFrameRectF.right + mHandleWidth;
|
|
float handleLineRightX = mFrameRectF.right + mHandleWidth;
|
|
|
float handleLineTopY = mFrameRectF.top - mHandleWidth;
|
|
float handleLineTopY = mFrameRectF.top - mHandleWidth;
|
|
|
float handleLineBottomY = mFrameRectF.bottom + mHandleWidth;
|
|
float handleLineBottomY = mFrameRectF.bottom + mHandleWidth;
|
|
|
|
|
+
|
|
|
|
|
+ // 画遮罩
|
|
|
|
|
+ if (mPaint == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ mPaint.setFilterBitmap(false);
|
|
|
|
|
+ int sc = canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null, Canvas.ALL_SAVE_FLAG);
|
|
|
|
|
+ canvas.drawBitmap(mBitmapCover, 0, 0, mPaint);
|
|
|
|
|
+ mPaint.setXfermode(xfermode);
|
|
|
|
|
+ canvas.drawBitmap(mBitmapRectBlack, handleLineLeftX, handleLineTopY, mPaint);
|
|
|
|
|
+ mPaint.setXfermode(null);
|
|
|
|
|
+ canvas.restoreToCount(sc);
|
|
|
|
|
+
|
|
|
|
|
+ //画4个角
|
|
|
|
|
+ mFramePaint.setColor(mHandleColor);
|
|
|
|
|
+ mFramePaint.setStyle(Paint.Style.FILL);
|
|
|
// 左上竖向
|
|
// 左上竖向
|
|
|
RectF ltRectFVertical =
|
|
RectF ltRectFVertical =
|
|
|
new RectF(handleLineLeftX, handleLineTopY, mFrameRectF.left, handleLineTopY + mHandleSize);
|
|
new RectF(handleLineLeftX, handleLineTopY, mFrameRectF.left, handleLineTopY + mHandleSize);
|
|
@@ -771,17 +792,7 @@ public class CropView extends View {
|
|
|
canvas.drawRect(rbRectFVertical, mFramePaint);
|
|
canvas.drawRect(rbRectFVertical, mFramePaint);
|
|
|
canvas.drawRect(rbRectFHorizontal, mFramePaint);
|
|
canvas.drawRect(rbRectFHorizontal, mFramePaint);
|
|
|
|
|
|
|
|
- // 画遮罩
|
|
|
|
|
- if (mPaint == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- mPaint.setFilterBitmap(false);
|
|
|
|
|
- int sc = canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null, Canvas.ALL_SAVE_FLAG);
|
|
|
|
|
- canvas.drawBitmap(mBitmapCover, 0, 0, mPaint);
|
|
|
|
|
- mPaint.setXfermode(xfermode);
|
|
|
|
|
- canvas.drawBitmap(mBitmapRectBlack, handleLineLeftX, handleLineTopY, mPaint);
|
|
|
|
|
- mPaint.setXfermode(null);
|
|
|
|
|
- canvas.restoreToCount(sc);
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|