gpt4 book ai didi

ios - iOS 的屏幕截图

转载 作者:行者123 更新时间:2023-12-01 19:14:25 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





iOS Screenshot part of the screen

(4 个回答)


7年前关闭。




我正在使用此代码进行 iOS 屏幕截图:

CGImageRef screen = UIGetScreenImage();
UIImage *image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
CGRect screenshotFrame;
CGImageRef screenshotRef = CGImageCreateWithImageInRect(screenshotRef, screenshotFrame);
UIImage * screenshot = [[(UIImage *)screenshotRef retain] autorelease];
CGImageRelease(screenshotRef);

但是我的屏幕包含屏幕底部的工具栏。我不想在捕获的屏幕上显示工具栏。如何裁剪工具栏?我怎样才能修改我的代码?

最佳答案

我认为您可以捕获 self.view 层,因为它是 Root View

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
//Retina display
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

玩得开心!

关于ios - iOS 的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14253204/

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