package com.example.demoproject;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
public class ImageCropMainActivity extends Activity{
protected ImageView bfImage;
protected Bitmap bitmap;
protected ExifInterface exif = null;
protected InputStream stream = null;
protected BitmapUtil bitmapUtil = new BitmapUtil();
protected Util util = new Util();
private static final int PIC_CROP = 1;
private int exifOrientation;
private int exifDegree;
private Uri uriPath;
private String path;
private String strpath;
private float mWidth;
private float mHeight;
private float mXLeft, mXRight , mYTop, mYBottom;
private static int mDep = 0;
Paint mPaint;
Bitmap mLSizeBmp;
Bitmap mRSizeBmp;
@SuppressLint("WrongCall")
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// setContentView(cv);
setContentView(R.layout.activity_image_crop_main);
bfImage = (ImageView) findViewById(R.id.bfImage);
bfImage.setVisibility(View.VISIBLE);
Intent getImage = this.getIntent();
BitmapFactory.Options options = new BitmapFactory.Options();
strpath = getImage.getStringExtra("Path");
uriPath = util.getPath(strpath);
try {
// recyle unused bitmaps
if (bitmap != null) {
bitmap.recycle();
}
stream = getContentResolver().openInputStream(uriPath);
bitmap = BitmapFactory.decodeStream(stream, null, options);
options.inSampleSize = 2;
mWidth = options.outWidth;
mHeight = options.outHeight;
this.bitmap = bitmapUtil.cropCenterBitmap(bitmap, (int)mWidth, (int)mHeight);
Cursor c = getContentResolver().query(uriPath, null,null,null,null);
c.moveToNext();
path = c.getString(c.getColumnIndex(MediaStore.MediaColumns.DATA));
c.close(); // close 는 finally로 빼야함
exif = new ExifInterface(path);
exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
exifDegree = bitmapUtil.exifOrientationToDegrees(exifOrientation);
bitmap = bitmapUtil.rotate(bitmap, exifDegree);
bfImage.setImageBitmap(bitmap);
CustomView cv = new CustomView(this);
cv.onDraw(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
class CustomView extends View {
public CustomView(Context context){
super(context);
}
protected void onDraw(Bitmap bitmap){
Canvas canvas = new Canvas(bitmap);
super.onDraw(canvas);
mLSizeBmp = BitmapFactory.decodeResource(getResources(), R.drawable.lefttop);
mRSizeBmp = BitmapFactory.decodeResource(getResources(), R.drawable.righttop);
mPaint = new Paint();
mPaint.setColor(Color.MAGENTA);
mPaint.setStrokeWidth(3);
mXLeft = mWidth / 5;
mXRight = mWidth * 4/5;
mYTop = mHeight / 5;
mYBottom = mHeight * 4/5;
mDep = bfImage.getWidth()/2;
// Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// mWidth = display.getWidth();
// mHeight = display.getHeight();
// Rect rect = new Rect(); // make Rect Class (Quadrangle)
// rect.set(0,0,canvas.getWidth(), canvas.getHeight()); // View Full Size Draw
// Paint paint = new Paint(); // Paint Object Create
// paint.setColor(Color.BLUE);
// paint.setStyle(Paint.Style.FILL);
// canvas.drawRect(rect, paint); // Rect draw paint
//=========================================//
//onDraw를 이용하여 Crop영역을 보여준다.
//=========================================//
Log.d("Good" , "mXLeft : " + mXLeft + " mYTop : " + mYTop + " mXRight : " + mXRight + "mYTop : " + mYTop + "mPaint : " + mPaint + "mDep : " + mDep);
canvas.drawBitmap(bitmap, 0, 0, null);
//상단 가로줄
canvas.drawLine(mXLeft, mYTop, mXRight, mYTop, mPaint);
//오른쪽 세로줄
canvas.drawLine(mXRight, mYTop, mXRight, mYBottom, mPaint);
//왼쪽 세로줄
canvas.drawLine(mXLeft, mYTop, mXLeft, mYBottom, mPaint);
//하단 가로줄
canvas.drawLine(mXLeft, mYBottom, mXRight, mYBottom, mPaint);
//왼쪽상단 아이콘
canvas.drawBitmap(mLSizeBmp, mXLeft - (mDep), mYTop- (mDep), null);
//오른쪽상단 아이콘
canvas.drawBitmap(mRSizeBmp, mXRight - (mDep), mYTop- (mDep), null);
//왼쪽하단 아이콘
canvas.drawBitmap(mRSizeBmp, mXLeft - (mDep), mYBottom- (mDep), null);
//오른쪽 하단 아이콘
canvas.drawBitmap(mLSizeBmp, mXRight - (mDep), mYBottom- (mDep), null);
//RECT SIZE
// Log.d("Rect","left : " + rect.left);
// Log.d("Rect","right : " + rect.right);
// Log.d("Rect","top : " + rect.top);
// Log.d("Rect","bottom: " + rect.bottom);
}
}
class Util {
public Uri getPath(String Path){
try {
if(Path == null){
Path = "";
}
} catch (Exception e) {
}
return Uri.parse(Path);
}
}
}

이 이미지 처럼 그릴려면 어떻게 해야하는지 제시점 해주세요.