1

Is it possible to display a PKDrawing on macOS that was previously created on an iOS device?

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571

1 Answers1

2

You can initialize a new PKDrawing object from your drawing data and generate a NSImage from it:

import PencilKit

do {
    let pkDrawing = try PKDrawing(data: drawingData)
    let nsImage = pkDrawing.image(from: pkDrawing.bounds, scale: view.window?.backingScaleFactor ?? 1)
} catch {
    print(error)
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • Do you know another way? Because rendering the image takes a huge amount of space and is very inefficient. – SwiftIsGreat Apr 08 '23 at 23:19
  • Not sure what you mean by "takes a huge amount of space". You are the only one who can decide the resolution and the type of data representation thats gonna be used. – Leo Dabus Apr 09 '23 at 00:06
  • The image is saved in a file. The resolution should be as high as possible, so the image consumes a lot of storage space (what I don't want), in contrast to the PKDrawing. Is it possible in any other way to represent the PKDrawing on macOS instead of an image? – SwiftIsGreat Apr 09 '23 at 00:26
  • Just save the drawingData – Leo Dabus Apr 09 '23 at 13:21
  • Sorry, I was stupid. I just discovered that PencilKit is not iOS only, I thought it was not available on macOS, but it is. Thank you for your help! – SwiftIsGreat Apr 09 '23 at 15:12