0

I am capturing images using Camera API and after clicking the image it is auto rotating it to 90 degree, to overcome this issue I am using Matrix to rotate the orientation by using following code:

 var angle = 90f
 val mat = Matrix()
 mat.postRotate(angle)

 val bmp = BitmapFactory.decodeStream(FileInputStream(picture), null, null)

//                    mat.postScale(1f, -1f, bmp!!.width / 2f, bmp.height / 2f);
 val correctBmp =
                Bitmap.createBitmap(bmp!!, 0, 0, bmp!!.width, bmp.height, mat, true)

But the issue is with this code it is successfully rotating the image to 90 degree but when i send the file to server then it uploads the file to server before rotating so i need a fix something like which can rotate the image inside the file too.

I have tried to write the bitmap inside a new file by using bitmap.compress but it is giving "broken pipe" error while uploading the image to server. So please suggest me any workaround for this.

sak
  • 1,230
  • 18
  • 37
  • get the exif information and then use that information to rotate the image – Shreemaan Abhishek Aug 05 '20 at 08:55
  • using exif it is possible to achieve this without using bitmap? – sak Aug 05 '20 at 09:20
  • The exifInterface API is the solution for you. This is a pre existing problem you will find solutions to this online – Shreemaan Abhishek Aug 05 '20 at 09:23
  • https://stackoverflow.com/questions/63261549/image-auto-rotates-to-90-degree-after-capturing-from-camera?noredirect=1#comment111866087_63261549 see this, he is using bitmap to change the rotation while i need to update the image file also as I have to send it to server. – sak Aug 05 '20 at 09:25
  • Does this answer your question? [Android get Orientation of a camera Bitmap? And rotate back -90 degrees](https://stackoverflow.com/questions/7286714/android-get-orientation-of-a-camera-bitmap-and-rotate-back-90-degrees) – Uuu Uuu Aug 05 '20 at 09:45
  • @UuuUuu No man, actually the problem is i want to change the orientation in the file itself – sak Aug 05 '20 at 10:22
  • The jpg file produced by the camera app contains the right rotation info. There is no need to change it if you wanna upload that .jpg file. So what are you doing that you did not tell us? – blackapps Aug 05 '20 at 11:11
  • `using exif it is possible to achieve this without using bitmap? ` Wrong question. A bitmap does not contain exif info. – blackapps Aug 05 '20 at 11:14
  • @blackapps When i am uploading the file to server then it is 90 degree rotated – sak Aug 05 '20 at 11:42
  • Then you upload wrong. And the file on server has a different size then the original!? Please show your code. – blackapps Aug 05 '20 at 13:36
  • no both are same and the clicked image in the file is also 90 degree rotated – sak Aug 05 '20 at 14:08

0 Answers0