在相机上捕获屏幕

时间:2014-05-29 18:45:40

标签: ios iphone camera

Helo Everyone。我想在相机出现时捕捉截图。方案是我向相机添加叠加视图。当用户调整相机和tapp捕捉按钮时。我想生成一个屏幕上的图像。我使用this代码尝试了屏幕截图,但只有覆盖图不是图像。那是相机是空白的。

我也见过this回答

但它只捕获图像而不是叠加视图

1 个答案:

答案 0 :(得分:1)

您可以从UIImagePickerController(代理人使用didFinishPickingMediaWithInfo方法收到的图片)中获取图像,并将其与您的叠加视图合并,如下所示:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    UIImage *cameraImage = The image captured by the camera;
    UIImage *overlayImage = Your overlay;
    UIImage *computedImage = nil;

    UIGraphicsBeginImageContextWithOptions(cameraImage.size, NO, 0.0f);
    [cameraImage drawInRect:CGRectMake(0, 0, cameraImage.size.width, cameraImage.size.height)];
    [overlayImage drawInRect:CGRectMake(0, 0, overlayImage.size.width, overlayImage.size.height)];

    computedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    dispatch_async(dispatch_get_main_queue(), ^{
       // don't forget to go back to the main thread to access the UI again
    });
});

编辑:我添加了一些dispatch_async以避免阻止用户界面