简体   繁体   English

如何使用AVCapture iOS捕获仅可见图像

[英]How to capture only visible image using AVCapture iOS

I am using AVCapture to capture the images from camera.Everything works fine except this issue. 我正在使用AVCapture从摄像机捕获图像。除此问题外,一切正常。

I need the final captured image as same like which is visible in camera.But the image shows more area(which is not like visible in camera).How can i get the same visible image as final stillImageOutput? 我需要最终捕获的图像与相机中可见的图像相同,但是图像显示的区域更大(这与相机中的可见图像不同)。我如何获得与最终stillImageOutput相同的可见图像?

Any help would be highly appreciated. 任何帮助将不胜感激。

use your view/imageview object name instead of contentScrollview. 使用您的视图/图像视图对象名称而不是contentScrollview。 This will help you to render the view and provide you an image. 这将帮助您渲染视图并提供图像。 for reference: https://charangiri.wordpress.com/2014/09/18/how-to-render-screen-taking-screen-shot-programmatically/ 供参考: https : //charangiri.wordpress.com/2014/09/18/how-to-render-screen-take-screen-shot-programmatically/

- (UIImage *) createScreenshotOfCompleteScreen
{
UIImage* image = nil;
UIGraphicsBeginImageContext(contentScrollview.contentSize);
{
    CGPoint savedContentOffset = contentScrollview.contentOffset;
    CGRect savedFrame = contentScrollview.frame;
    contentScrollview.contentOffset = CGPointZero;
    contentScrollview.frame = CGRectMake(0, 0, contentScrollview.contentSize.width, contentScrollview.contentSize.height);
    if ([[NSString versionofiOS] intValue]>=7)
    {
        [contentScrollview drawViewHierarchyInRect:contentScrollview.bounds afterScreenUpdates:YES];
    }
    else
    {
        [contentScrollview.layer renderInContext: UIGraphicsGetCurrentContext()];
    }
    image = UIGraphicsGetImageFromCurrentImageContext();
    contentScrollview.contentOffset = savedContentOffset;
    contentScrollview.frame = savedFrame;
}
UIGraphicsEndImageContext();
return image;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM