gpt4 book ai didi

iOS 5 : adding a caption to a camera image

转载 作者:行者123 更新时间:2023-11-29 11:18:00 25 4
gpt4 key购买 nike

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

目前不担心用户将如何输入此文本,任何人都可以给我一些关于如何向使用 UIImagePickerController 拍摄的图像添加一些文本的建议吗?

最佳答案

  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();

关于iOS 5 : adding a caption to a camera image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8600913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com