-1

In my app, when image taken from camera it rotates and lost in Samsung tab sometimes, in Other tab it works well always.

    public void onActivityResult(int requestCode, int resultCode, Intent data){
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {

     Bitmap bmp = (Bitmap) data.getExtras().get("data");
                        ByteArrayOutputStream stream = new ByteArrayOutputStream();

                        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
                        byte[] byteArray = stream.toByteArray();
                        imageFront=stream.toByteArray();
                        // convert byte array to Bitmap

                        Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

                        BitmapDrawable bdrawable = new BitmapDrawable(getContext().getResources(), bitmap);
                        String aa    = getContext().getPackageCodePath();
                        Toast.makeText(getActivity(), aa,
                                Toast.LENGTH_LONG).show();

                        FrontView.setBackground(bdrawable);
}
}
}
Janaka
  • 398
  • 5
  • 16

1 Answers1

0

If I understand you correctly you've got problem that some devices return rotated bitmap from camera, right?

Check ExifInterface class

You can also check this post -> Why does an image captured using camera intent gets rotated on some devices on Android?

Community
  • 1
  • 1
Peter Moskala
  • 360
  • 1
  • 9
  • Thanks for the idea, how to get 'photoPath' there ? – Janaka May 12 '17 at 11:05
  • You can save bitmap to file into internal storage. You can also pass input stream (which you can create from bitmap) to ExifInterface constructor, but I haven't tested it yet. – Peter Moskala May 12 '17 at 11:14