0

In my app the user has the opportunity to take pictures and then view it in an ImageView. The problem is the image when viewing the photo turns 90 dregrees (if i take in portrait it appears in landscape). What am i doing wrong??

Taking photo:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "/PROJETOS/"+nome+"/"+"proj"+id+"_reg"+id_reg+"_"+valor+".jpg");
nome_caminho = "proj"+id+"_reg"+id_reg+"_"+valor+".jpg";
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);   



protected void onActivityResult(int requestCode, int resultCode, Intent data){

    if (requestCode == TAKE_PICTURE){
        mydb.execSQL("INSERT INTO fotos(id_regi,nome,caminho) VALUES('"+id_reg+"','"+nome_caminho+"','"+outputFileUri+"')");

    }

Viewing it:

Options op = new Options();  
    op.inSampleSize = 5;   
    op.inJustDecodeBounds = false;  
    bm = BitmapFactory.decodeFile(caminhoNovo, op); 
    foto.setImageBitmap(bm);
  • Is it the same for portrait photos (portrait -> landscape)? Or is it just landscape photos turning portrait? – Husman May 29 '14 at 13:47
  • turns always 90 degrees, if i take in portrait, turns 90 degrees. If i take in landscape it appears upsidedown. Turns always 90 degrees from the way i take it – user2257792 May 29 '14 at 13:49
  • Normally phones which have a camera button on their right side (like sony phones), they assume that user should click pics keeping phone in landscape mode such that phone resembles more like a proper camera (like say cybershot pocket camera). So when you take a pic you have to be careful about phone's orientation. Most sony phone takes care of this in their native camera app. – Kaustuv May 29 '14 at 13:53
  • you need to change the exif for your photo before saving – Meenal May 29 '14 at 13:54
  • If i try to use the phone's gallery (when the user clicks the photo in my app it goes to the default gallery) will it show the way it should?? – user2257792 May 29 '14 at 13:57
  • Can you check how the images are saved on your SD card - using the default image browser on your phone? Are they saved such that they are rotated BEFORE the save or is your code for viewing the code rotating them when opening the image? – Husman May 29 '14 at 13:59
  • In the SD card (gallery) they are ok. The code to view the photo is above, i have nothing else in my code – user2257792 May 29 '14 at 14:01
  • Have you tried loading the images without any options: bm = BitmapFactory.decodeFile(caminhoNovo); – Husman May 29 '14 at 14:08
  • Yes, it's the same. One thing that i noticed is that, my images are in a listview and then the user clicks in the photo and goes to the ImageView. The image already appears turned in the ListView – user2257792 May 29 '14 at 14:17

1 Answers1

0

Just turn it by 90 degree

Matrix matrix=new Matrix();
imageView.setScaleType(ScaleType.MATRIX);   //required
float angle = 90f;//Use your value
matrix.postRotate( angle, imageView.getDrawable().getBounds().width()/2, imageView.getDrawable().getBounds().height()/2);
imageView.setImageMatrix(matrix);
Sripathi
  • 1,760
  • 15
  • 20
  • That's not a solution. If the code/bug is fixed later on, his images will be turned by -90 degrees because of your code. It's best to find the underlying issue and fix it. – Husman May 29 '14 at 13:52
  • @Husman The image is turned in some specific devices, it might Samsung Ace, Samsung S II and so on. In those devices the images are stored after rotation. For that case we need to revert it manually. – Sripathi May 29 '14 at 14:02