Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 拍摄一张iiOS图像的屏幕截图_Objective C_Image Processing_Uiimageview_Screenshot - Fatal编程技术网

Objective c 拍摄一张iiOS图像的屏幕截图

Objective c 拍摄一张iiOS图像的屏幕截图,objective-c,image-processing,uiimageview,screenshot,Objective C,Image Processing,Uiimageview,Screenshot,我想在iOS应用程序中截取我屏幕上特定部分的屏幕截图。附加的图像就是屏幕的这一部分。在这里,我想截图的红色标记的矩形区域包含3个UIImageViews,其中包含一个白色的图像框架在背景上,一个图像与咖啡杯和咖啡上的苹果标志图像分别 我正在使用以下代码来完成此操作 - (UIImage *)captureView:(UIView *)view withArea:(CGRect)screenRect { UIGraphicsBeginImageContext(screenRect.si

我想在iOS应用程序中截取我屏幕上特定部分的屏幕截图。附加的图像就是屏幕的这一部分。在这里,我想截图的红色标记的矩形区域包含3个UIImageViews,其中包含一个白色的图像框架在背景上,一个图像与咖啡杯和咖啡上的苹果标志图像分别

我正在使用以下代码来完成此操作

- (UIImage *)captureView:(UIView *)view withArea:(CGRect)screenRect {

    UIGraphicsBeginImageContext(screenRect.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextFillRect(ctx, screenRect);

    [view.layer renderInContext:ctx];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage ;
}
像这样称呼它

UIImage *viewImage = [self captureView:self.FrameImageView withArea:self.FrameImageView.bounds];
此处FrameImageView是一个UIImageView,它在背景中包含白色图像帧

但我得到的结果图像如下所示

我认为问题是,我的代码正在拍摄FrameImageView层的屏幕截图。这就是为什么我只得到背景帧。但我希望屏幕截图包含FrameImageView上的其他2个UIImageView,以及第一个图像的红色矩形部分

谁能帮我,怎么解决这个问题。提前感谢。

试试这个变体

 UIGraphicsBeginImageContextWithOptions(FrameImageView.frame.size, YES, 4);

 [_myStreetView drawViewHierarchyInRect:FrameImageView.frame afterScreenUpdates:YES];

 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

 UIImageView *img = [[UIImageView alloc] initWithImage:image];
试试这个变体

 UIGraphicsBeginImageContextWithOptions(FrameImageView.frame.size, YES, 4);

 [_myStreetView drawViewHierarchyInRect:FrameImageView.frame afterScreenUpdates:YES];

 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

 UIImageView *img = [[UIImageView alloc] initWithImage:image];
试试这个:

- (UIImage*)captureView:(UIView *)yourView {
    CGRect rect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [yourView.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
试试这个:

- (UIImage*)captureView:(UIView *)yourView {
    CGRect rect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [yourView.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

试试这个:试试这个:谢谢…但是这里的_myStreetView是什么?我已经测试了代码,请在这里查看它的输出…实际上,我认为你需要为self.view或任何包含图像视图内容的父视图制作一个屏幕截图。把结果裁剪成红色矩形我也这么认为。我的代码完美地截取了self.view的屏幕截图。但是在裁剪图像时,我无法获得FrameImageView的实际CGRect。FrameImageView.frame.bounds给出(0,0180180),因此裁剪的图像从父视图的左上角开始。不确定我是否在让CGrect获取FrameImageView的位置时出错。你能帮我吗?FrameImageView的父视图是self.view?谢谢…但是这里的_myStreetView是什么?我已经测试了代码,请查看这里的输出…实际上,我认为你需要对self.view或任何包含图像视图内容的父视图进行截图。把结果裁剪成红色矩形我也这么认为。我的代码完美地截取了self.view的屏幕截图。但是在裁剪图像时,我无法获得FrameImageView的实际CGRect。FrameImageView.frame.bounds给出(0,0180180),因此裁剪的图像从父视图的左上角开始。不确定我是否在让CGrect获取FrameImageView的位置时出错。你能帮我吗?FrameImageView的父视图是self.view?