I would like to adjust the PKStrokePoint of the canvas drawing in the PencilKit API.
The code below should generate the same strokes, but the drawing doesn't generate well depending on the type of pen selected.
func generate_sameDrawing(drawing :PKDrawing) -> PKDrawing{
var newDrawingStrokes : [PKStroke] = []
for stroke in drawing.strokes {
var newPoints : [PKStrokePoint] = []
stroke.path.forEach { (point) in
let newPoint = PKStrokePoint(location: point.location,
timeOffset: point.timeOffset,
size: point.size,
opacity: point.opacity,
force: point.force,
azimuth: point.azimuth,
altitude: point.altitude)
newPoints.append(newPoint)
}
let newPath = PKStrokePath(controlPoints: newPoints, creationDate: Date())
let newStroke = PKStroke(ink: PKInk(stroke.ink.inkType, color: stroke.ink.color), path: newPath)
newDrawingStrokes.append(newStroke)
}
let newDrawing = PKDrawing(strokes: newDrawingStrokes)
return newDrawing
}
Here is an image showing the result.
The pen and marker generate exactly the same drawing, but with pencil type, the thickness and opacity of the stroke change, and the stroke location also moves a little.
If you find any bugs/mistakes do let me know.