如何在视频顶部添加图层并将其保存为iOS

时间:2016-05-17 11:25:40

标签: ios swift replace avplayer avplayerlayer

我有一个视频,我想在它上面添加一个图层并保存它。我不知道这是否有效,但到目前为止,我仍然坚持到这里。

       self.avPlayerLayer.addSublayer(self.imageView.layer)

然后我如何保存视频并替换之前的视频?

这是绘图代码

  override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

    if self.drawing.selected == true {
        //NSLog(@"touchmoved");
        print("draw")
        let touch: UITouch = touches.first!
        let currentPoint: CGPoint = touch.locationInView(self.view)
        print("self.ImageView.image = \(self.imageView.frame)")

        // First We Set We need to begin the uigraphicsbeginimage so that we can draw the image
        UIGraphicsBeginImageContext(CGSizeMake(self.imageView.frame.width, self.imageView.frame.height))

        //Drawing board frame
        self.imageView.image?.drawInRect(self.imageView.frame)

        //Drawing Atiitrbutes
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), .Round)
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush)
        CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), self.drawColor.CGColor)
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(), .Normal)
        CGContextBeginPath(UIGraphicsGetCurrentContext())
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), self.lastPoint.x, self.lastPoint.y)
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y)
        CGContextStrokePath(UIGraphicsGetCurrentContext())
        print("UIGRAPHICS  = \(UIGraphicsGetImageFromCurrentImageContext())")

        //Set image to image
        self.imageView.image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        self.lastPoint = currentPoint
        self.view.setNeedsDisplay()

    }
}

0 个答案:

没有答案