15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swift iOS8カメラ制御(撮影、保存)

Posted at

準備はキャプチャセッションのセットアップを参照

1、画像を取得
2、取得した画像をJpegに変換
3、JpegからUIImageを作成してアルバムに追加

//カメラにつながっているコネクションを選択
let videoConnection = ImageOut.connectionWithMediaType(AVMediaTypeVideo)
        
//接続から画像を取得
self.ImageOut.captureStillImageAsynchronouslyFromConnection(videoConnection, 	completionHandler:
	{(imageDataBuffer: CMSampleBuffer?, error:NSError?)->Void in
    	if(imageDataBuffer == nil){
             //error
       }
                
       //取得したImageのDataBufferをJpegに変換
      let imageData: NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataBuffer)
                
       //JpegからUIImageを作成
       let image : UIImage = UIImage(data: imageData)!
                
       //アルバムに追加
       UIImageWriteToSavedPhotosAlbum(image, self, nil, nil)
    }
)

github StillCamera Capture

15
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?