我想在另一张图片上添加图片和一些文字,然后制作一张图片。我必须添加文本,但无法弄清楚如何添加图像。有什么帮助吗?
答案 0 :(得分:2)
这段代表假设你有一个名为bottomImage的UIImage用于绘制基础图像,topImage将被绘制在bottomImage的上方(上方)。 xpos,ypos是浮点数,用于描述将绘制topImage的目标x,y(左上角)位置,targetSize是在bottomImage上绘制topImage的大小。
...
UIGraphicsBeginImageContext( bottomImage.size );//create a new image context to draw offscreen
[bottomImage drawInRect:CGRectMake(0,0,bottomImage.size.width,bottomImage.size.height)];//draw bottom image first, at original size
[topImage drawInRect:CGRectMake(xpos,ypos,targetSize.width,targetSize.height) blendMode:kCGBlendModeNormal alpha:1];//draw the image to be overlayed second, at wanted location and size
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();//get newly drawn image context into a UIImage
UIGraphicsEndImageContext();//stop drawing to the context
return newImage;//return/use the newly created image
这不是线程安全的 - 不建议在线程中创建UIImage。