I'm working on a function that takes a photo and convert it to base64 string. But for some reason, and i tried looking this up, Convert.ToBase64String
always rotate my image 90 degrees counter clockwise. I have tried looking this up but couldnt find anyone with similair issue. Here's the code
private async Task<string> GetPhotoBase64StringAsync(int compressionQuality = 50, PhotoSize photoSize = PhotoSize.Medium)
{
string filename = $"{DateTime.Now.ToString("MMddyyyy_Hmmtt")}.jpg";
var photo = await UtilityService.OpenCameraAsync(filename, compressionQuality, photoSize);
if (photo != null)
{
var bytes = await photo.GetStream().ConvertToBytes();
var base64string = Convert.ToBase64String(bytes);
return base64string
}
return string.Empty;
}
photo
is an object that is returned by the xamarin plugin that im using. I know for a fact that the plugin returns the image in the right orientation because i displayed afterward and its not rotated.
The problem happens when i convert the image to stream and from stream to base64. If i put a breakpoint at return base64string
and copy and paste the base64 string to an online base64 to image convert, the image would come out rotated 90 degrees counter clockwise.
I have also tried
var base64string = bytes.ToBase64String();
but that didnt work either.
This is so strange and i have never countered this before.