ios - How can I save an image taken through AVCaptureSession -
I have set a custom camera view, which is the overlay button on the scene. Everything works as it should. The camera takes the picture, and the picture appears in the UIImageView. How can I save this image once in UIImageView?
Code below:
ViewController.h
@ View Interface Viewer: UIViewController & lt; UIImagePickerControllerDelegate, UINavigationControllerDelegate & gt; {} @protecti (strong, non-monomitive) IBotlate UIUUUI * framefactor; @protecti (strong, nonmomic) IBolet UIImageView * imageView; - (IBAction) LEFOTO: (ID) sender;
ViewController.m
@ View implementation controller AVCapture session * session; AVCaptureStillImageOutput * stillImageOutput; - (zero) viewDidoadload [[Super Viewedload]; // Setup an additional after loading the view, usually from a nib } - (Zero) ViewVillage: (BOOL) animated {session = [[A Wikipedia session alloc] INS]; [Session set sessionprayset: AVCepture sessionPreset photo]; AVCaptureDevice * Input Devices = [AVCaptureDevice Default DeviceWithMediaType: AVMediaTypeVideo]; NSError * error; AVCaptureDeviceInput * deviceInput = [AVCaptureDeviceInput DeviceInputWidth Device: Input Device Error: & amp; Error]; If ([session canAddInput: deviceInput]) {[session addInput: deviceInput]; } AVCaptureVideoPreviewLayer * previewLayer = [[AVCaptureVideo previewlayer alloc] initWithSession: session]; [PreviewLayer set videogravity: AVLair videogwism recycledofffil]; CALayer * rootLayer = [[Self View] Layer]; [Rootletier set masks tabbeds: yes]; CGRTF frame = self.frameForCapture.frame; [Previewlayer setframe: frame]; [Routular entry scissor: index on previewlayer: 0]; StillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary * outputSettings = [[NSDI allocon] Initwith object endase: AVVDOKDJJPEG, AVVDOKODEK, ZERO]; [StillImageOutput setOutputSettings: outputSettings]; [Session addOutput: stillImageOutput]; [Start the session]; } - (IBAction) LEFOTO: (ID) sender {AVCaptureConnection * videoConnection = NIL; (For [[AVCaptureInputPort * port in connection input ports]) {if ([[port mediaType] isqual: AVMediaTypeVideo]) {videoConnection = connection; for connection to AVCaptureConnection * connection). break; }} If (video connection) {break; }} [StillImageOutput captureStillImageAsynchronouslyFromConnection: videoConnection completionHandler: ^ (CMSampleBufferRef imageDataSampleBuffer, NSError * error) {if (imageDataSampleBuffer! = Null) {NSData * imageData = [AVCaptureStillImageOutput jpegStillImageNutRepresentation: imageDataSampleBuffer]; UIImage * image = [UIImage imageWithData: imageData]; Self.imageView.image = image; }}]; } - (zero) did risiv memorialisation [[super daviditamammy warning]; // Any resource settlement which can be reproduced. } @end
You can use this function to save image in the tool
UIImageWriteToSavedPhotosAlbum (UIImage * image, ID completion goal, SEL completion selector, zero * referencesInfo);
You only need to complete the Goal, the complete selector and the reference interface if you want to notify when saving the image, otherwise you can pass in zero.
Comments
Post a Comment