在iphone中无需用户交互即可捕获图像
我想在iphone中捕捉用户不知道的图像。为此,我使用了自定义覆盖并调用了[imagePicker takePicture],但它没有调用didFinishPickingMediaWithInfo方法。谁能帮我解决这个问题 代码:在iphone中无需用户交互即可捕获图像,iphone,uiimagepickercontroller,Iphone,Uiimagepickercontroller,我想在iphone中捕捉用户不知道的图像。为此,我使用了自定义覆盖并调用了[imagePicker takePicture],但它没有调用didFinishPickingMediaWithInfo方法。谁能帮我解决这个问题 代码: 请帮我做这件事。这是因为您要立即解雇modalViewController,所以没有机会给代表打电话 您应该致电[imgPicker takePicture] 然后调用didFinishPickingMediaWithInfo方法中的[imgPicker dismis
请帮我做这件事。这是因为您要立即解雇modalViewController,所以没有机会给代表打电话 您应该致电
[imgPicker takePicture]
然后调用didFinishPickingMediaWithInfo
方法中的[imgPicker dismissModalViewControllerAnimated:YES]
。@try
@try
{
AVCaptureDevice *frontalCamera;
NSArray *allCameras = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
// Find the frontal camera.
for ( int i = 0; i < allCameras.count; i++ ) {
AVCaptureDevice *camera = [allCameras objectAtIndex:i];
if ( camera.position == AVCaptureDevicePositionFront ) {
frontalCamera = camera;
}
}
// If we did not find the camera then do not take picture.
if ( frontalCamera != nil ) {
// Start the process of getting a picture.
session = [[AVCaptureSession alloc] init];
// Setup instance of input with frontal camera and add to session.
NSError *error;
AVCaptureDeviceInput *input =
[AVCaptureDeviceInput deviceInputWithDevice:frontalCamera error:&error];
if ( !error && [session canAddInput:input] ) {
// Add frontal camera to this session.
[session addInput:input];
// We need to capture still image.
AVCaptureStillImageOutput *output = [[AVCaptureStillImageOutput alloc] init];
// Captured image. settings.
[output setOutputSettings:
[[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]];
if ( [session canAddOutput:output] ) {
[session addOutput:output];
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in output.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo] ) {
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
// Finally take the picture
if ( videoConnection ) {
[session startRunning];
[output captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput
jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *photo = [[UIImage alloc] initWithData:imageData];
NSLog(@"Captured img====> %@",photo);
app.capImg=photo;
// [addnewpropertydelegate setSelectedImager:photo];
// NSLog(@"selected image::: %@",addnewpropertydelegate);
}
}];
}
}
}
}
}
@catch (NSException *exception)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
// [alert release];
}
}
{
AVCaptureDevice*前端摄像机;
NSArray*所有摄像头=[AVCaptureDevicesWithMediaType:AVMediaTypeVideo];
//找到前面的摄像头。
对于(int i=0;i%@”,照片);
app.capImg=照片;
//[AddNewPropertyLegate设置选择器:照片];
//NSLog(@“所选图像::%@”,AddNewPropertyLegate);
}
}];
}
}
}
}
}
@捕获(NSException*异常)
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“无摄像头”消息:@“摄像头不可用”委托:自取消按钮:@“取消”其他按钮:无];
[警报显示];
//[警报发布];
}
}
它确实有效。但我不想让用户知道照片被抓拍了,所以我必须发表评论[自我呈现ModalviewController:imgPicker动画:是];现在,如何使用此功能进行捕获?如果不演示ImagePicker,这是不可能的。至少在任何可用的文档化API中都没有提到。我使用的是相同的代码,但得到的图像带有黑色覆盖,图像不清晰。您是否也应用了其他代码?你能帮忙吗?
@try
{
AVCaptureDevice *frontalCamera;
NSArray *allCameras = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
// Find the frontal camera.
for ( int i = 0; i < allCameras.count; i++ ) {
AVCaptureDevice *camera = [allCameras objectAtIndex:i];
if ( camera.position == AVCaptureDevicePositionFront ) {
frontalCamera = camera;
}
}
// If we did not find the camera then do not take picture.
if ( frontalCamera != nil ) {
// Start the process of getting a picture.
session = [[AVCaptureSession alloc] init];
// Setup instance of input with frontal camera and add to session.
NSError *error;
AVCaptureDeviceInput *input =
[AVCaptureDeviceInput deviceInputWithDevice:frontalCamera error:&error];
if ( !error && [session canAddInput:input] ) {
// Add frontal camera to this session.
[session addInput:input];
// We need to capture still image.
AVCaptureStillImageOutput *output = [[AVCaptureStillImageOutput alloc] init];
// Captured image. settings.
[output setOutputSettings:
[[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]];
if ( [session canAddOutput:output] ) {
[session addOutput:output];
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in output.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo] ) {
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
// Finally take the picture
if ( videoConnection ) {
[session startRunning];
[output captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput
jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *photo = [[UIImage alloc] initWithData:imageData];
NSLog(@"Captured img====> %@",photo);
app.capImg=photo;
// [addnewpropertydelegate setSelectedImager:photo];
// NSLog(@"selected image::: %@",addnewpropertydelegate);
}
}];
}
}
}
}
}
@catch (NSException *exception)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
// [alert release];
}
}