UIImage to String without converting JPG/PNG/HEIC

Hello Gurus,
We would like to convert UIImage the raw binary data to string and reverse the string to UIImage object.

At most of the place we found below block.
Code Block
extension String {
func toImage() -> UIImage? {
if let data = Data(base64Encoded: self, options: .ignoreUnknownCharacters){
return UIImage(data: data)
}
return nil
}
}

Is there any way to convert UIImage to String without converting JPG/PNG/HEIC ?

Replies

Have a look here:

https://stackoverflow.com/questions/4623931/get-underlying-nsdata-from-uiimage


When initialising a UIImage object with init(data: originalData), that originalData will be converted into raw data in some kind of internal format. These data can be retrieved later with

Code Block
let rawData = myImage.cgImage?.dataProvider?.data as Data?

However because the rawData is raw, it is going to be even larger than when using UIImagePNGRepresentation.
Hope that helps.