当我将图片添加到IB中的ImageView时-确定! 但是,当我在代码中添加图片时,ImageView会使图片变平,并且看起来很难看。 这是我的代码: 为什么会这样? 谢谢! ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我尝试在UIImageView中显示相机的图片。
我尝试调试我的应用程序(@属性(非原子,弱)IBOutlet UILabel * messageLabel;),
-------行“ [[output captureStillImageAsynchronouslyFromConnection ...”的输出
我在通话前已分配了值。 (self.messageLabel.text = @“ before !!”;我从来没有@@“ Test !!”)
变量结果的返回为“ OK”
我使用的权利:com.apple.security.device.camera
您能帮我调试更多细节吗?
这是我的代码
-(NSString*) takePhoto
{
AVCaptureDevice *frontalCamera;
AVCaptureSession *photoSession;
NSString* result;
NSArray *allCameras = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for ( int i = 0; i < allCameras.count; i++ )
{
AVCaptureDevice *camera = [allCameras objectAtIndex:i];
if ( camera.position == AVCaptureDevicePositionFront )
{
frontalCamera = camera;
}
}
if ( frontalCamera != nil )
{
photoSession = [[AVCaptureSession alloc] init];
NSError *error;
AVCaptureDeviceInput *input =
[AVCaptureDeviceInput deviceInputWithDevice:frontalCamera error:&error];
if ( !error && [photoSession canAddInput:input] )
{
[photoSession addInput:input];
AVCaptureStillImageOutput *output = [[AVCaptureStillImageOutput alloc] init];
[output setOutputSettings:
[[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]];
if ( [photoSession canAddOutput:output] )
{
[photoSession 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; }
}
if ( videoConnection )
{
[photoSession startRunning];
result = @"Let's Go ?";
self.messageLabel.text = @"before !!";
[output captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
self.messageLabel.text = @"Test !!";
if (imageDataSampleBuffer != NULL)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *photo = [[UIImage alloc] initWithData:imageData];
self.vImage.image = photo;
}
}];
result = @"OK";
}
}
}
}
return result;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.