I get a base64 string from the server, then I parse it to image, on Android side, the image is rotated to 270 degree, its width/height is exchanged than iOS side. Any idea? Thank you. Here is the code: Android code:
val decodedByteArray: ByteArray = Base64.decode(base64Str, Base64.DEFAULT)
val bitmap = BitmapFactory.decodeByteArray(decodedByteArray, 0, decodedString.size)
Timber.i("image size: ${bitmap.width}, ${bitmap.height}")
iOS code:
if let photoData = Data(base64Encoded: base64Str, options: .ignoreUnknownCharacters),
let photo = UIImage(data: photoData) {
printLog("photo size: \(photo.size)")
cell.ivPhoto.image = photo
}
Check if your image has a rotation angle in its EXIF tag. The Bitmapfactory does not perform any EXIF rotations/transformations at all.
Use the ExifInterface class to get such information. Remember to use the AndroidX variant instead of the deprecated framework one.
If such is the case, then you must rotate the image according to the EXIF angle. This operation will require to create a new bitmap, therefore in order to avoid a potential OutOfMemoryError, use some of the tips provided in this link.