0
私はカメラアプリを作っていて、アプリ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)
}
}
}
私はすでにcalturedImage.imageを使用していましたが、写真アルバムに黒い画像を保存しました。 – coding22
私のコードを編集しました。キャプチャされた画像とラベルを除いて、写真のアルバムに保存するためにすべてが表示されています。 – coding22
これは機能しました! – coding22