iPhone - UIImagePickerController 截屏?

发布于 2024-09-15 06:33:06 字数 834 浏览 0 评论 0原文

我正在尝试使用以下代码从我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2024-09-22 06:33:06

您想要使用新的(在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文