Um ein Foto zu machen, verwende ich die Kamera auf dem Gerät installiert. Das Foto ist in der Galerie gespeichert, wird aber immer horizontal gespeichert.
Wie behebe ich es?
Bild in der Galerie wird mit falscher Ausrichtung gespeichert
Dies ist die Absicht, wenn Sie auf die Schaltfläche "Foto hinzufügen":
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
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = null;
photoURI = galleryAddPic();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
Dies ist die Methode createImageFile()
:
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
imageFileName = "JPG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
Am Ende wird dies die Methode galleryAddPic()
:
private Uri galleryAddPic(){
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
return contentUri;
}
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
Nachdem ich das Foto in die Galerie eingefügt habe, kann ich das Bild so drehen, wie ich es möchte. Aber in der Galerie wird das Bild nicht gut gedreht.
Also möchte ich das Bild in der Galerie mit der richtigen Ausrichtung speichern.
Danke!
Ich mache dies bereits in einer Methode, um das Bild in einer imageview.and -Funktion anzuzeigen, aber ich muss das Bitmap drehen und dann in der Galerie speichern – Ibernato933
@lbernato überprüfen Sie die aktualisierte Antwort. –
Ja, aber vor dem methos addGalleryPic, Bitmap in sull, wenn ich decodeBitmap (Pfad) aufrufen. Wenn Sie ein Foto machen, wie wird das Bitmap reaktiviert? – Ibernato933