I am trying to generate a base64 string from the same image in swift and c#, come out the base64 string are different but similar, is it suppose the base64 string should be same if generated from the same image?
The base64 string result in swift
/9j/4AAQSkZJRgABAQAASABIAAD/..................
The base64 string result in c#
/9j/4AAQSkZJRgABAQEAYABgAAD/..................
And i have proved that one from swift is invalid base64 string, that one from c# is valid. is it any problem on my swift script?
//swift
let image : UIImage = UIImage(named:"a.jpg")!
var strBase64 = image.jpegData(compressionQuality: 1)?.base64EncodedString() ?? ""
//c#
private string GenString()
{
byte[] bytes = GetFileByteArray(@"C:\temp\a.jpg");
return Convert.ToBase64String(bytes);
}
private byte[] GetFileByteArray(string filename)
{
FileStream oFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
byte[] FileByteArrayData = new byte[oFileStream.Length];
oFileStream.Read(FileByteArrayData, 0, System.Convert.ToInt32(oFileStream.Length));
oFileStream.Close();
return FileByteArrayData;
}