Retrieve image from TextureResource and convert it to base64string

Is there any way to convert TextureResource to Image

Here's a rough outline with some links. TextureResource includes routines for copying to a MTLTexture:

https://developer.apple.com/documentation/realitykit/textureresource#Copying-the-texture

and MTLTexture includes routines for copying to an image:

https://developer.apple.com/documentation/Metal/MTLTexture#Copying-data-from-a-texture-image

You should be able to use this data to create a CGBitmapContext:

https://developer.apple.com/documentation/coregraphics/cgcontext/init(data:width:height:bitspercomponent:bytesperrow:space:bitmapinfo:)-10b3i

Which you can make into an image:

https://developer.apple.com/documentation/coregraphics/cgcontext/makeimage()

Then you can save the CGImage to an CGImageDestination (presumably created using CGImageDestinationCreateWithData(::::)):

https://developer.apple.com/documentation/imageio/cgimagedestinationaddimage(::_:)

Then, after calling CGImageDestinationFinalize(_:), you can convert the data object into a base64string by converting the CFDataObject into an NSData object and calling base64EncodedString(options:).

I haven't tried this, but I expect it or something very similar should work. If you have any questions about the details in parts listed above let me know. I'm glad to talk about any of the parts listed above in greater detail.

Retrieve image from TextureResource and convert it to base64string
 
 
Q