Изображение, сохраненное в галерее, повернуто и имеет неправильную дату (1970) - PullRequest
0 голосов
/ 17 марта 2019

В моем приложении приведенный ниже код позволяет пользователю открыть камеру, сделать фотографию и сохранить ее в галерее, код работает и фотография сохраняется в галерее, но проблема в том, что фотография отображается в галерее повернутойи в конце галереи с датой, равной 1970, пожалуйста, кто-то может помочь мне решить эти две проблемы?Заранее спасибо.Ниже мой код: код захвата фотографии:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File

        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "myapplication.project",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, CAMERA_CAPTURE_TAG);
        }
    }
}

код создания файла изображения:

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    currentPhotoPath = image.getAbsolutePath();
    return image;
}

способ сохранения фотографии в галерее:

public final void notifyMediaStoreScanner(final File file) {
    try {
        MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(),
                file.getAbsolutePath(), file.getName(), null);
        getApplicationContext().sendBroadcast(new Intent(
                Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

Метод OnActivityResult:

if (requestCode == CAMERA_CAPTURE_TAG && resultCode == Activity.RESULT_OK) {
        //Bundle extras = data.getExtras();
        //imageBitmap = (Bitmap) extras.get("data");
        //imageSelected.setImageBitmap(imageBitmap);


        File f =new File(currentPhotoPath);
       notifyMediaStoreScanner(f);

    }
...