【问题标题】:iPhone - UIImagePickerController take screen shots?iPhone - UIImagePickerController 截屏?
【发布时间】:2010-08-21 22:09:36
【问题描述】:

我正在尝试使用以下代码从我的 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];
}

【问题讨论】:

    标签: iphone uiimagepickercontroller screen-capture


    【解决方案1】:

    您想使用新的(在 OS 4 中)AVFoundation API。

    试试这个页面了解一些信息:

    http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html

    【讨论】:

    • 谢谢,这似乎是最好的方法,但到目前为止我收到的数据无法转换为 uiimage。我会更新
    • 我发布的链接中的示例代码应该会有所帮助。下半部分是一行,上面写着。那时 yiu 有一个 uiimage 可以做你喜欢的事情。
    • 是的,一切正常,我收到了 captureOutput,但是当我将它转换为 uiimage 并创建一个 imageview 并将其添加到我的视图时,uiimageview 不显示图片,我认为数据不知何故被打断。这是否可以在 iphone 3g 上运行?因为 iphone 3g 不允许视频录制。
    • 问题是它阻塞了主线程,所以在开始捕获 ui 后被锁定,我尝试在线程上运行它,似乎它不是线程安全的。
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多