I'm currently trying to do something fairly simple... just trying to decode then encode an image in Swift 5.
I've been able to see that my image is indeed correct, but it seems like whenever I try to encode the base64 string in Swift, it won't load at all into my UIImageView.
I've run the base64 decoded string in online converters and the image is correctly formatted.
Did I do anything stupid? Thanks so much for any help you can provide!
The Decode Process (currently seems to be working)
let b64 = UIImagePNGRepresentation(tempImage);
var tempImage2 = b64?.base64EncodedString(options: .endLineWithLineFeed);
if (tempImage2 == nil) {
tempImage2 = "";
}
And the encoding process / loading into the image view:
if let data = Data(base64Encoded: tempImage2!, options: .ignoreUnknownCharacters) {
var useImage = UIImage(data: data);
imageView.image = useImage
print("and now the image view should show it??");
}
On printing the decoded base64, everything seems correct. As soon as I run the encoding, however, nothing is being loaded into my UIImageView - just blankness.