重叠一个图像而不是另一个 [英] overlap one image over another

查看:88
本文介绍了重叠一个图像而不是另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个图像上添加图像和一些文字,并创建一个图像。我必须添加文本,但无法弄清楚如何添加图像。有什么帮助吗?

I want to add image and some text on another image and create a single image. I have got to add text but not able to figure out that how to add image. Any help?

推荐答案

这段代表假设你有一个名为bottomImage的UIImage用于绘制基本图像,topImage将是在底部图像上方(上方)绘制。 xpos,ypos是用于描述将绘制topImage的目标x,y(左上角)位置的浮点数,而targetSize是用于在bottomImage上绘制topImage的大小。

This snippet assumes you have UIImage's named bottomImage for the base image to be drawn upon, and topImage that will be drawn ON (above) the bottomImage. xpos,ypos are floats to describe the target x,y (top left) position where topImage will be drawn, and targetSize the size in which topImage will be drawn on bottomImage.

...
    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。

This is not thread safe - creating a UIImage in a thread is not recommended.

这篇关于重叠一个图像而不是另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆