public CropImage(Context context, AttributeSet attr) {
super(context, attr);
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point point = new Point();
display.getSize(point);
mWidth = point.x;
mHeight = point.y;
sx = mWidth / 5; // 초기 Crop선의 위치 설정
ex = mWidth * 4 / 5;
sy = mHeight / 5;
ey = mHeight * 4 / 5;
// sx = mWidth;
// ex = mWidth;
// sy = mHeight;
// ey = mHeight;
Log.e(TAG, outFilePath);
cnxt = (ImageCropActivity) context;
// 비트맵 크기 조절(메모리 문제로 인하여 1/2 크기로)
BitmapFactory.Options resizeOpts = new Options();
resizeOpts.inSampleSize = 2;
try {
bitmap = BitmapFactory.decodeStream(
new FileInputStream(outFilePath), null, resizeOpts);
} catch (Exception e) {
e.printStackTrace();
}
bitmap = Bitmap.createScaledBitmap(bitmap, (int) mWidth, (int) mHeight,
false);
Log.e(TAG, "" + bitmap.getHeight() * bitmap.getWidth());
hBmp = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.shape);
wBmp = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.shape);
// 페인트 설정
pnt = new Paint();
pnt.setColor(Color.MAGENTA);
pnt.setStrokeWidth(3);
}
첨에 배치할때 crop 상자가 그림에 꽉찬 상태로 나오고 싶은데요 부탁드립니다.
public boolean onTouchEvent(MotionEvent e) {
int x = (int) e.getX();
int y = (int) e.getY();
if (e.getAction() == MotionEvent.ACTION_DOWN) {
oldx = x;
oldy = y;
// 눌려진곳이 선 근처인가 확인
if ((x > sx - DEP) && (x < sx + DEP))
bsx = true;
else if ((x > ex - DEP) && (x < ex + DEP))
bex = true;
if ((y > sy - DEP) && (y < sy + DEP))
bsy = true;
else if ((y > ey - DEP) && (y < ey + DEP))
bey = true;
// 어느 하나라도 선택이 되었다면 move에서 값 변경
if ((bsx || bex || bsy || bey))
bMove = false;
else if (((x > sx + DEP) && (x < ex - DEP))
&& ((y > sy + DEP) && (y < ey - DEP)))
bMove = true;
return true;
}
if (e.getAction() == MotionEvent.ACTION_MOVE) {
if (bsx)
sx = x;
if (bex)
ex = x;
if (bsy)
sy = y;
if (bey)
ey = y;
// 사각형의 시작 라인보다 끝라인이 크지않게 처리
if (ex <= sx + DEP) {
ex = sx + DEP;
return true;
}
if (ey <= sy + DEP) {
ey = sy + DEP;
return true;
}
// 움직인 거리 구해서 적용
if (bMove) {
dx = oldx - x;
dy = oldy - y;
sx -= dx;
ex -= dx;
sy -= dy;
ey -= dy;
// 화면밖으로 나가지않게 처리
if (sx <= 0)
sx = 0;
if (ex >= mWidth)
ex = mWidth - 1;
if (sy <= 0)
sy = 0;
if (ey >= mHeight)
ey = mHeight - 1;
}
invalidate(); // 움직일때 다시 그려줌
oldx = x;
oldy = y;
return true;
}
비율 널어주는건 어떻게 계산하는지 x,y 좌표 ㅜㅜ 너무 어렵습니다.