2016-08-18 58 views
0

这必须已经问过,但我不能找到一个参考..我用下面的代码创建图像(感谢本·莫罗)watchOS - 有没有办法将在手表上绘制的图像保存到PhotoLibrary?

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 
     } 
    } 

有没有一种方法所得到的图像保存到照片库? 感谢

回答

1

我的猜测是,你可以将图像传送到使用WCSessiontransferFile:metadata:的iOS应用程序,然后使用UIImageWriteToSavedPhotosAlbum()函数保存图像。

我发现this example这可能是有帮助的,但请注意,根据我的经验,通过WCSession发送数据的限制大小没有记录。这就是为什么我建议使用transferFile。

+0

谢谢Josip,非常有帮助。 –

相关问题