iPhone - UIImagePickerController 截屏?
我正在尝试使用以下代码从我的 uiimagePickerController 获取屏幕截图,
UIGraphicsBeginImageContext(imagePicker.view.bounds.size);
[self.imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
它显示除了从相机捕获的内容之外的所有内容,我看到取消按钮,拍照按钮。 相机上显示的不是它捕捉到的黑屏,有什么办法可以解决这个问题吗?或者有更好的方法每 1 秒自动从相机捕获图像?
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
UIImageView *img = [[UIImageView alloc] initWithImage:image];
[img setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:img];
[img release];
}
I am trying to use the following code to take screen shots from my uiimagePickerController
UIGraphicsBeginImageContext(imagePicker.view.bounds.size);
[self.imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
It shows everything except what is capturing from the camera, i see the cancel button, take photo buttom.
Instead of what is displaying on the camera it's capturing a black screen, is there any way around this? or a better way to automatically capture an image from camera every 1 seconds?
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
UIImageView *img = [[UIImageView alloc] initWithImage:image];
[img setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:img];
[img release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要使用新的(在 OS 4 中)AVFoundation API。
尝试此页面获取一些信息:
http://developer.apple.com /iphone/library/qa/qa2010/qa1702.html
You want to use the new (in OS 4) AVFoundation APIs.
Try this page for some info:
http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html