好吧,要在图像上添加文本,我相信您可以只使用文本字段来获取输入,然后将文本放入标签中。这部分可以通过几种不同的方式完成,但相当容易。
至于抓取所有图层的组合图像,您可以使用 Quartz。
每个UIWindow
(继承自UIView
)UIView
并由 CALayer 支持。该CALayer/-renderInContext:
方法允许您将图层及其子图层渲染到图形上下文。因此,要获取整个屏幕的快照,您可以遍历屏幕上的每个窗口并将其层层次结构渲染到目标上下文。完成后,您可以通过该UIGraphicsGetImageFromCurrentImageContext
功能获取屏幕截图,如下所示。
请注意,CALayer/-renderInContext:
仅捕获您的 UIKit 和 Quartz 绘图。它不捕获 OpenGL ES 或视频内容。
#import <QuartzCore/QuartzCore.h>
......
- (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 UIGraphicsBeginImageContext
CGSize 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 front
for (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 image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
至于上传到 Facebook 和 Twitter 看看ShareKit。它是一个拖放库,用于与 Facebook、Twitter、Tumblr、电子邮件等共享。拥有它会为您的应用程序增加价值。我建议实施它。