objective-c – 使用UIButton截取UIView的截图

objective-c – 使用UIButton截取UIView的截图,第1张

概述我正在尝试使用一个按钮创建一个应用程序,该按钮将截取设备屏幕上绘制的对象的屏幕截图并将其保存在设备的照片库中… 我怎么能这样做?任何的想法? Apple在此描述了一种方法: http://developer.apple.com/library/ios/#qa/qa1703/_index.html - (UIImage*)screenshot {// Create a graphics cont 我正在尝试使用一个按钮创建一个应用程序,该按钮将截取设备屏幕上绘制的对象的屏幕截图并将其保存在设备的照片库中…

我怎么能这样做?任何的想法?

解决方法 Apple在此描述了一种方法: http://developer.apple.com/library/ios/#qa/qa1703/_index.html

- (UIImage*)screenshot {// Create a graphics context with the target size// On iOS 4 and later,use UIGraphicsBeginImageContextWithOptions to take the scale into consIDeration// On iOS prior to 4,fall back to use UIGraphicsBeginImageContextCGSize imageSize = [[UIScreen mainScreen] bounds].size;if (NulL != UIGraphicsBeginImageContextWithOptions)    UIGraphicsBeginImageContextWithOptions(imageSize,NO,0);else    UIGraphicsBeginImageContext(imageSize);CGContextRef context = UIGraphicsGetCurrentContext();// Iterate over every window from back to frontfor (UIWindow *window in [[UIApplication sharedApplication] windows]) {    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])    {        // -renderInContext: renders in the coordinate space of the layer,// so we must first apply the layer's geometry to the graphics context        CGContextSaveGState(context);        // Center the context around the window's anchor point        CGContextTranslateCTM(context,[window center].x,[window center].y);        // Apply the window's transform about the anchor point        CGContextConcatCTM(context,[window transform]);        // Offset by the portion of the bounds left of and above the anchor point        CGContextTranslateCTM(context,-[window bounds].size.wIDth * [[window layer] anchorPoint].x,-[window bounds].size.height * [[window layer] anchorPoint].y);        // Render the layer hIErarchy to the current context        [[window layer] renderInContext:context];        // Restore the context        CGContextRestoreGState(context);    }}// RetrIEve the screenshot imageUIImage *image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();return image;}

并记住#import< QuartzCore / QuartzCore.h>

总结

以上是内存溢出为你收集整理的objective-c – 使用UIButton截取UIView的截图全部内容,希望文章能够帮你解决objective-c – 使用UIButton截取UIView的截图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1080082.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存