[英]UIimageview plus Text overlay saved as NEW image?
I know there are more than enough resources on how have a text box overlay on a portion of an image view. 我知道在文本视图的一部分上如何覆盖文本框方面有足够的资源。 However, is there any way to save the image + overlaid text as a new image upon upload? 但是,有什么方法可以在上传图片时将图片+覆盖的文字另存为新图片吗?
Is this possible? 这可能吗? How? 怎么样?
You can do this using Core Graphics/Quartz 2D. 您可以使用Core Graphics / Quartz 2D执行此操作。 I'm not too experienced with Core Graphics myself, but check out the documentation here that describes loading a graphic context with an image, which you can then save out to a file after modifying, or just drawing an image from scratch and saving it out: 我本人对Core Graphics不太熟悉,但是请查看此处的文档,该文档描述了如何使用图像加载图形上下文,然后可以在修改后将其保存到文件中,或者仅从头开始绘制图像并将其保存出来。 :
Link 1: Drawing/Printing for iOS 链接1: iOS版绘图/打印
Link 2: Quartz 2D Programming Guide 链接2: Quartz 2D编程指南
Quick example of drawing text from the Quartz 2D Programming Guide under the "Text" section: Quartz 2D编程指南中“文本”部分下的绘图文本快速示例:
void MyDrawText (CGContextRef myContext, CGRect contextRect) // 1
{
float w, h;
w = contextRect.size.width;
h = contextRect.size.height;
CGAffineTransform myTextTransform; // 2
CGContextSelectFont (myContext, // 3
"Helvetica-Bold",
h/10,
kCGEncodingMacRoman);
CGContextSetCharacterSpacing (myContext, 10); // 4
CGContextSetTextDrawingMode (myContext, kCGTextFillStroke); // 5
CGContextSetRGBFillColor (myContext, 0, 1, 0, .5); // 6
CGContextSetRGBStrokeColor (myContext, 0, 0, 1, 1); // 7
myTextTransform = CGAffineTransformMakeRotation (MyRadians (45)); // 8
CGContextSetTextMatrix (myContext, myTextTransform); // 9
CGContextShowTextAtPoint (myContext, 40, 0, "Quartz 2D", 9); // 10
}
Here's what the code does: 代码是这样的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.