0

I want to send a PNG file from a SwiftUI app to a BLE device 128 bytes at a time. Ideally, I would like to resize the PNG (from 50x50 to 150x150) before sending and ensure it is RBG565 format. How do I get the data from a PNG in the right format and size in SwiftUI?

I was going to use CIImage and pngData(), but read this solution which recommends using the following, however I don't have the pixelBuffer:

let ciImage = CIImage(cvImageBuffer: pixelBuffer)
let ciContext = CIContext()
guard let cgImage = ciContext.createCGImage(ciImage, from: ciImage.extent) else { return }
let image = UIImage(cgImage: cgImage)

It also doesn't cover the RBG565 conversion. I read this, but was hoping no additional package was needed. This thread is 10 years old and the solution is command line, which doesn't work in this case unless I apply it to the source files. I'm not sure of the source format and how to determine if it needs to be converted. I did see some apple documentation on it, but could not really determine if this was the right approach.

Once I have that I can loop through and send 128 bytes at a time. I have the BLE part working, just need the loop once I get the right data.

For development purposes I just dragged a PNG into the Xcode assets, but the intent is to download a PNG from the internet and store it as a file. I'm not sure if this changes anything.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
lcj
  • 1,355
  • 16
  • 37

0 Answers0