I am developing an app using android native camera. I can successfully take a photo and store and display on ImageView. I am testing on HTC desire Z, Nexus S and Motorola Zoom. It works on all three devices except one issue on Nexus S. When I take a photo using Nexus S, the preview image has been rotated by 90 degrees.
Can you please let me know how to over come this issue?
My code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera_preview);
imgTakenPhoto = (ImageView) findViewById(R.id.imageView);
getPhotoClick();
}
private File getTempFile()
{
return new File(Environment.getExternalStorageDirectory(), "image.tmp");
}
private void getPhotoClick()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(getTempFile()));
startActivityForResult(intent, REQUEST_FROM_CAMERA);
}
InputStream is=null;
@Override
protected void onActivityResult(int requestcode, int resultCode, Intent data){
if (requestcode == REQUEST_FROM_CAMERA && resultCode == RESULT_OK) {
File file=getTempFile();
try {
is=new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(is==null){
try {
Uri u = data.getData();
is=getContentResolver().openInputStream(u);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Bitmap thumbnail = BitmapFactory.decodeStream(is);
imgTakenPhoto.setImageBitmap(thumbnail);
}
}
I have taken help from Problems saving a photo to a file
Many Thanks
Anyone please?