【问题标题】:iOS 5: adding a caption to a camera imageiOS 5:为相机图像添加标题
【发布时间】:2011-12-22 07:59:58
【问题描述】:

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

目前不担心用户将如何输入此文本,谁能给我一些建议,告诉我如何将一些文本添加到使用 UIImagePickerController 拍摄的图像中?

【问题讨论】:

  • 你的意思是你想在图像上画一些文字?或者将文本添加到图像的元数据中?
  • 是的,在图像本身上绘制文本。

标签: ios uiimagepickercontroller


【解决方案1】:
  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();

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多