I am making a camera-based application where I put a rectangular view on the camera. When I shoot an image with new Camera.PictureCallback(), I crop this image so that it gets part of the rectangle. Well, that works fine.
Now I have implemented View.OnTouchListenerand used this so that I make the form moveable.
So, I need to capture an image with the user's final choice, for example, where they put the rectangle. 
Bitmap imageOriginal = BitmapFactory.decodeByteArray(data, 0, data.length);
float scale = 1280 / 1000;
int left = (int) (scale * (imageOriginal.getWidth() - 250) / 2);
int top = (int) (scale * (imageOriginal.getHeight() - 616) / 2);
int width = (int) (scale * 750);
int height = (int) (scale * 616);
Bitmap imageConverted = Bitmap.createBitmap(imageOriginal, left, top, width, height, null, false);
This is the method that I used to crop the image. The values are rigidly attached to find the exact position. Now I need values for this top, bottom, top, width with a changing rectangle.
// customView,
public class CustomView extends View {
private Paint paint = new Paint();
public CustomView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);
paint.setStrokeWidth(10);
int x0 = canvas.getWidth()/2;
int y0 = canvas.getHeight()/2;
int dx = canvas.getHeight()/3;
int dy = canvas.getHeight()/3;
canvas.drawRect(x0-dx, y0-dy, x0+dx, y0+dy, paint);
}
}
//
Camera.PictureCallback mPicture = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
fileName = "IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()).toString() + ".jpg";
File mkDir = new File(sdRoot, dir);
mkDir.mkdirs();
File pictureFile = new File(sdRoot, dir + fileName);
try {
Bitmap imageOriginal = BitmapFactory.decodeByteArray(data, 0, data.length);
float scale = 1280 / 1000;
int left = (int) (scale * (imageOriginal.getWidth() - 250) / 2);
int top = (int) (scale * (imageOriginal.getHeight() - 616) / 2);
int width = (int) (scale * 750);
int height = (int) (scale * 616);
Bitmap imageConverted = Bitmap.createBitmap(imageOriginal, left, top, width, height, null, false);
FileOutputStream purge = new FileOutputStream(pictureFile);
imageConverted.compress(Bitmap.CompressFormat.JPEG, 100, purge);
purge.flush();
purge.close();
} catch (FileNotFoundException e) {
Log.d("DG_DEBUG", "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d("DG_DEBUG", "Error accessing file: " + e.getMessage());
}
try {
ProjectManager.getInstance().settings.IMAGE_LOCATION = "/sdcard/" + dir + fileName;
exif = new ExifInterface(ProjectManager.getInstance().settings.IMAGE_LOCATION);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + orientation);
exif.saveAttributes();
mView.saveImage(dir + fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
};