2011-12-22 89 views
1

我正在构建一个简单的应用程序,允许用户拍摄将保存在相册中的照片。因为我希望用户能够拍摄大量看起来相似但不相同的物体的图像(例如,房屋中的家具的细节),所以我想在图像上添加一个小文本标题来描述图像的内容。iOS 5:为相机图像添加标题

不用担心用户如何在此刻输入此文本,任何人都可以给我一些建议,以了解如何将一些文本添加到使用UIImagePickerController拍摄的图像中?

+0

你的意思是你想画一些文字上的形象呢?或者向图片的元数据添加文字? – 2011-12-22 08:16:37

+0

是的,在图片上绘制文字。 – futureshocked 2011-12-22 10:10:43

回答

2
  1. 创建一个新的图形上下文。
  2. 将图像绘制到上下文中。
  3. 在上面画上文字。
  4. 从上下文创建新图像。

代码应该是这样的:

UIGraphicsBeginImageContextWithOptions(sourceImage.size, YES, sourceImage.scale); 
[sourceImage drawAtPoint:CGPointZero]; 

NSString *caption = @"Hello World"; 
UIFont *captionFont = [UIFont boldSystemFontOfSize:24.0]; 
[[UIColor whiteColor] setFill]; // or setStroke? I am not sure. 
[caption drawAtPoint:CGPointMake(10.0f, 10.0f) withFont:captionFont]; 

UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

太容易了,谢谢! – futureshocked 2011-12-23 00:21:31