0

This must have been asked before, but I cannot find a reference.. I'm creating an image by the code below (thanks to Ben Morrow)

 let rect = panGesture.objectBounds()
        switch panGesture.state {
        case .began:
            randomColor()

            previousPoint1 = panGesture.locationInObject()

            // create backward projection
            let velocity = panGesture.velocityInObject()
            // the pan gesture recognizer requires some movement before recognition
            // this multiplier accounts for the delay
            let multiplier: CGFloat = 1.75
            previousPoint2 = CGPoint(x: previousPoint1.x - exponentialScale(velocity.x) * multiplier,
                                     y: previousPoint1.y - exponentialScale(velocity.y) * multiplier)

        case .changed:
            let currentPoint = panGesture.locationInObject()

            // draw a curve through the two mid points between three points. The middle point acts as a control point
            // this creates a smoothly connected curve
            // a downside to this apprach is that the drawing doesn't reach all the way to the the user's finger touch. We create forward and backward projections with the velocity to account for the lag
            let actualImage = curveThrough(a: previousPoint2, b: previousPoint1, c: currentPoint, in: rect)
            savedImage = actualImage

            // create forward projection
            let velocity = panGesture.velocityInObject()
            let projectedPoint = CGPoint(x: currentPoint.x + exponentialScale(velocity.x), y: currentPoint.y + exponentialScale(velocity.y))
            let projectedImage = curveThrough(a: previousPoint1,
                                              b: currentPoint,
                                              c: midPoint(currentPoint, projectedPoint),
                                              in: rect,
                                              with: 0.5)
            // show the forward projection but don't save it
            canvasGroup.setBackgroundImage(projectedImage)

            previousPoint2 = previousPoint1
            previousPoint1 = currentPoint

        case .ended:
            let currentPoint = panGesture.locationInObject()
            let image = curveThrough(a: previousPoint2, b: previousPoint1, c: currentPoint, in: rect)
            canvasGroup.setBackgroundImage(image)
            savedImage = image
        default:
            break
        }
    }

Is there a way to save the resulting image to a photo library? Thanks

ICL1901
  • 7,632
  • 14
  • 90
  • 138

1 Answers1

1

My guess is that you can transfer an image to iOS application using WCSession transferFile:metadata: and then save image using UIImageWriteToSavedPhotosAlbum() function.

I found this example which might be helpful but please note, from my experience, sending data over WCSession has restricted size which isn't documented. That is why I suggested using transferFile.

Community
  • 1
  • 1
Josip B.
  • 2,434
  • 1
  • 25
  • 30