簡體   English   中英

如何將帶有標簽的圖像保存到相冊?

[英]How do I save an image with a label on it to the photo album?

我正在制作一個相機應用程序,我想為在應用程序MSQRD中拍攝的照片添加標簽,然后保存到相冊中。 我得到了要顯示在圖像上的標簽,但是當我進入相冊時,它顯示的是圖像但沒有標簽。 我的代碼在做什么錯。 這是我當前使用的代碼:

@IBAction func takePicture(sender: AnyObject) {


if let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
            videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
            stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(sampleBuffer, error) in
                if (sampleBuffer != nil) {

                    let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
                    let dataProvider = CGDataProviderCreateWithCFData(imageData)
                    let cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, CGColorRenderingIntent.RenderingIntentDefault)
                    let image = UIImage(CGImage: cgImageRef!, scale: 1.0, orientation: UIImageOrientation.Right)




        //edited this part it saves the entire view in the photo album except for the image that was taken and the label. 
       UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0)
                    self.view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
                    let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
                    UIGraphicsEndImageContext()




                    //saves captured picture to camera roll.
                    UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil)





                    //fade in the image that was taken
                    UIView.animateWithDuration(0.5, delay: 0.1, options: UIViewAnimationOptions.CurveLinear, animations: {

                        self.capturedImage.image = image
                        self.capturedImage.alpha = 1.0

                        }, completion: nil)
                        }
                        }
                        }

您是從UIGraphicsImageContext capturedImage ,但從未使用過。 UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)更改為UIImageWriteToSavedPhotosAlbum(capturedImage, nil, nil, nil)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM