gpt4 book ai didi

iphone - 从 UIVIEW+ipad 截图

转载 作者:行者123 更新时间:2023-12-03 20:27:58 25 4
gpt4 key购买 nike

我想截取viewcontroller的屏幕截图我写过这个:-

- (UIImage *)captureScreenInRectWOScroll:(CGRect)captureFrame {    
CALayer *layer;
layer = self.view.layer;
UIGraphicsBeginImageContext(captureFrame.size);
CGContextClipToRect (UIGraphicsGetCurrentContext(),captureFrame);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenImage;
}

我调用此方法的方式:-

UIImage *img_woscroll1 =[self captureScreenInRectWOScroll:CGRectMake(35,147,497,260)];

我想从下面的附图中截取地址的屏幕截图:- enter image description here

当我从上面的代码中截取屏幕截图时,我得到的图像在顶部有很多空白(顶部的绿色图像),如果图像:-

enter image description here

请帮助我..如何从图像中获取正确的屏幕截图,这样我就不会在顶部看到空白图像。

最佳答案

试试这个

UIGraphicsBeginImageContext(myView.frame.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data=UIImagePNGRepresentation(viewImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *strPath = [documentsDirectory stringByAppendingPathComponent:@"myimage.png"];
[data writeToFile:strPath atomically:YES];

关于iphone - 从 UIVIEW+ipad 截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10946615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com