2

I'm creating a view that will allow me to draw over a given bitmap.

As I create the canvas I set the bitmap as the base for it. It works perfectly on an emulator but, when I try to use it on my phone it behave strangely and rotate the bitmap by 90 degrees.

Here is how I create the canvas. I get the right backgroundPicture from my previous activity.

    mBitmap = backgroundPicture.copy(Bitmap.Config.ARGB_8888, true);
    mBitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true);
    mCanvas = new Canvas(mBitmap);

ANd here are the screenshots

When I take the picture : When I take the picture

What it displays in my recycler view (displays normally) recycler view display

What it displays on the canvas (90 degrees on the left) weird display

Thank you for your help, I'm not used to work with canvases so I'm a bit lost :/

Matthieu Meunier
  • 458
  • 5
  • 21
  • Can you share the code that computes `width` & `height`? – Doron Yakovlev Golani Mar 21 '18 at 14:47
  • Sure, here it is `public void init(DisplayMetrics metrics, Uri picUri) { int height = metrics.heightPixels; int width = metrics.widthPixels; }` – Matthieu Meunier Mar 21 '18 at 14:50
  • It seems like the image orientation creates the problem. Perhaps you can check that and rotate the whole thing (replace width and height & rotate the canvas as you draw) – Doron Yakovlev Golani Mar 21 '18 at 14:57
  • I thought about that but I can't understand why on the emulator it works just fine :/ That's what really bothering me, the huge difference in the behaviour on one device and another – Matthieu Meunier Mar 21 '18 at 15:02
  • I suggest you look at this: https://stackoverflow.com/questions/12726860/android-how-to-detect-the-image-orientation-portrait-or-landscape-picked-fro?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Doron Yakovlev Golani Mar 21 '18 at 15:11
  • I tried to get the orientation of the image but it gives me a rotation value of 0. So if I believe my ExifInterface I have a rotated image that isn't "officialy" rotated :/ – Matthieu Meunier Mar 22 '18 at 08:01

1 Answers1

2

After some digging it appears that the problem comes from my smartphone, a Samsung Galaxy A3. In some Samsung models the camera is rotated to gain place for the others components of the phone. Some Samsung handle the difference but if they don't you'll get an rotation of 0 and you'll have to handle the rotation problem model by model manually.

I hope this will help other people.

Cordially, Matthieu

Matthieu Meunier
  • 458
  • 5
  • 21