在图像上添加文本我相信您可以使用文本字段来获取输入,然后将文本放入标签中。这部分可以通过几种不同的方式完成,但相当容易。
就抓取所有图层的组合图像而言,您可以使用 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、电子邮件等共享。拥有它会为您的应用程序增加价值。我建议实施它。