照片库等效

时间:2015-04-23 18:25:25

标签: ios objective-c ios-simulator uiimagepickercontroller

这个uiimagepickercontroller方法是否有等价物,如果在iOS模拟器中测试应用程序,则使用照片库中的通用照片?我想使用AVFoundation / AVCam。

-(void)takePhoto {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
imagePickerController.sourceType =     UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType =     UIImagePickerControllerSourceTypeCamera;
#endif
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;

[self presentModalViewController:imagePickerController animated:YES];
}

方法2

 - (void)snapStillImage //this is being called on did load
{

dispatch_async([self sessionQueue], ^{
// Update the orientation on the still image output video connection before capturing.
[[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];
// Flash set to Auto for Still Capture
[ViewController5 setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];
// Capture a still image.
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
    if (imageDataSampleBuffer)
    {
        NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];

        photo.image = [[UIImage alloc] initWithData:imageData];
        [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[photo.image CGImage] orientation:(ALAssetOrientation)[photo.image imageOrientation] completionBlock:nil];
        [self uploadPhoto];
}
}];
});
}

0 个答案:

没有答案
相关问题