I have made a Custom Camera app and I am showing my image in an imageview after the camera Click. But here I am facing a problem that the image I captured always set in changed orientation.
i.e If I capture the pic while taking my camera as Portrait it don’t set the image as Portrait, It changes the orientation.
Here is the camera click code :-
@Override
public void onPictureTaken(byte[] data, Camera camera) {
//here we write the code for saving the picture onto the sdCard
File pictureFileDir = getDir();
//to check whether directory exists or not!!
if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
//Log.d(Constants.DEBUG_TAG, "Can't create directory to save image.");
Toast.makeText(Irant_Custom_cameraApplication.this, "Can't create directory to save image.",
Toast.LENGTH_LONG).show();
return;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
String date = dateFormat.format(new Date());
photo_file="Picture_"+date+".jpg";
photo_FileName = pictureFileDir.getPath()+File.separator+photo_file;
picture_file = new File(photo_FileName);
FileOutputStream outStream = null;
try{
Toast.makeText(getApplicationContext(), "Image captured!", Toast.LENGTH_LONG).show();
outStream = new FileOutputStream(picture_file);
outStream.write(data);
outStream.close();
String imgpath = photo_file;
System.out.println("Path for the image*********************"+photo_file);
SignupDetails.imagePath=imgpath;
}
catch (Exception e) {
Log.d("Image save error :", e.getMessage());
}
}
};
It’s not always implemented the same for each device, some rotate automatically, others don’t. I think the best approach is to look at the EXIF data of the file. That’s your best bet.