大家好我想在出现相机时捕获屏幕截图。场景是我向相机添加一个叠加视图。并且当用户调整摄像头和Tapp捕获按钮时。我想生成图像在屏幕上。我已经尝试过使用this代码进行屏幕截图,但是仅覆盖图像而不是图像。那是相机是空白的。
我也看到了this答案
但它仅捕获图像而不覆盖叠加视图
最佳答案
您可以获取从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以避免阻塞UI