Создайте диалоговое окно с просьбой сохранить или отменить фотографию чуть выше кода (код для сохранения рисунка) и вызвать код, который вы описали только внутри прослушивателя onclick кнопки ok.
В следующем коде само приложение камеры по умолчанию запрашивает сохранить или отменить после захвата изображения диалогового Put
mCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (taken_image == null) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
image_uri = fileUri;
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
startActivityForResult(intent, 1);
mEdit.setVisibility(View.VISIBLE);
dialog.cancel();
}
}
});
@Override
public void onActivityResult(int requestCode, int resultCode,
final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == 1) {
if (image_uri != null)
try {
ExifInterface exif = new ExifInterface(image_uri.getPath()); // Since API Level 5
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
// TODO
upload_image_hd = BitmapFactory.decodeFile(image_uri
.getPath());
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
Rotate90Bitmap(upload_image_hd, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Rotate180Bitmap(upload_image_hd, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
Rotate270Bitmap(upload_image_hd, 270);
break;
case ExifInterface.ORIENTATION_NORMAL:
RotateBitmap(upload_image_hd, 0);
break;
default:
RotateBitmap(upload_image_hd, 0);
break;
}
} catch (OutOfMemoryError e) {
Toast.makeText(getActivity(),
e + "\"memory exception occured\"",
Toast.LENGTH_LONG).show();
taken_image = null;
round_Image = null;
upload_image_hd = null;
} catch (Exception e) {
Toast.makeText(getActivity(), e + "\"exception occured\"",
Toast.LENGTH_SHORT).show();
taken_image = null;
round_Image = null;
upload_image_hd = null;
}
public Bitmap RotateBitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
round_Image = Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
// get the base 64 string
imgString = Base64.encodeToString(getBytesFromBitmap(round_Image),
Base64.NO_WRAP);
uploadProfilePicture_bytes();
return Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
}
public Bitmap Rotate90Bitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
round_Image = Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
// get the base 64 string
imgString = Base64.encodeToString(getBytesFromBitmap(round_Image),
Base64.NO_WRAP);
uploadProfilePicture_bytes();
return Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
}
public Bitmap Rotate180Bitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
round_Image = Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
// get the base 64 string
imgString = Base64.encodeToString(getBytesFromBitmap(round_Image),
Base64.NO_WRAP);
uploadProfilePicture_bytes();
return Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
}
public Bitmap Rotate270Bitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
round_Image = Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
// get the base 64 string
imgString = Base64.encodeToString(getBytesFromBitmap(round_Image),
Base64.NO_WRAP);
uploadProfilePicture_bytes();
return Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
}
после взятия фото –
@MD почему вы сделали downvote? –
Nono Я просто читаю ваш ответ, я заметил нисходящее движение, это потрясающий ответ, спасибо! – NeoVe