I am new in android devlopment. I am making a camera app i stuck at point i got so many solution already on net but my problem is not solve please help. I am automaticly capturing the image and uploading this on server But i get all the image in landscape mode with correct orientation else are not in correct orientation. At time of preview my display is rotating right but image orientation of capture image is not right My code is
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
try {
Camera.Parameters parameters= camera.getParameters();
parameters = camera.getParameters();
//camera.setParameters(parameters);
setCameraDisplayOrientation(Preview.this,0, camera, parameters);
//camera.setParameters(parameters);
parameters.getPictureSize();
parameters.setPictureSize(w, h);
parameters.getPreviewSize();
parameters.setPreviewSize(w, h);
camera.startPreview();
} catch(Exception e) {
Log.d(TAG, "Cannot start preview", e);
}
}
public static void setCameraDisplayOrientation(Activity activity,
int cameraId, android.hardware.Camera camera, Camera.Parameters parameters {android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
//parameters.setRotation(result);
camera.setDisplayOrientation(result);
camera.setParameters(parameters);
}