Когда я нажимаю кнопку, камера захватывает изображение, я хочу выполнить кадрирование на этом изображении после кадрирования, но я не могу определить проблему, потому что функция кадрирования не работает должным образом, Пожалуйста, помогите мне разобратьсяпроблема, которая является основной причиной функции кадрирования, не выполняется заранее
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
final int CAMERA_CAPTURE = 1;
final int CROP_PIC = 2;
private Uri picUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button captureBtn = (Button) findViewById(R.id.capture_btn);
captureBtn.setOnClickListener((View.OnClickListener) this);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.capture_btn) {
try {
// use standard intent to capture an image
Intent captureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
// we will handle the returned data in onActivityResult
startActivityForResult(captureIntent, CAMERA_CAPTURE);
} catch (ActivityNotFoundException anfe) {
Toast toast = Toast.makeText(this, "This device doesn't support the crop action!",
Toast.LENGTH_SHORT);
toast.show();
}
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Toast toast4 = Toast.makeText(this, Integer.toString(RESULT_OK),
Toast.LENGTH_SHORT);
toast4.show();
if (resultCode == RESULT_OK) {
Toast toast = Toast.makeText(this, "capture ok",
Toast.LENGTH_SHORT);
toast.show();
if (requestCode == CAMERA_CAPTURE) {
// get the Uri for the captured image
picUri = data.getData();
// Toast toast1 = Toast.makeText(this, Integer.toString(requestCode),
// Toast.LENGTH_SHORT);
// toast1.show();
performCrop();
}
// user is returning from cropping the image
if (requestCode == CROP_PIC) {
Toast toast1 = Toast.makeText(this, "crop ok",
Toast.LENGTH_SHORT);
toast1.show();
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
ImageView picView = (ImageView) findViewById(R.id.picture);
picView.setImageBitmap(thePic);
}
}
}
/**
* this function does the crop operation.
*/
private void performCrop() {
////////////////// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_PIC);
}
catch (ActivityNotFoundException anfe) {
Toast toast3 = Toast
.makeText(this, "This device doesn't support the crop action!", Toast.LENGTH_SHORT);
toast3.show();
}
}
}