Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何使用NSString draw功能从文本创建UIImage并将此图像与另一个UIImage组合_Iphone_Objective C_Ios - Fatal编程技术网

Iphone 如何使用NSString draw功能从文本创建UIImage并将此图像与另一个UIImage组合

Iphone 如何使用NSString draw功能从文本创建UIImage并将此图像与另一个UIImage组合,iphone,objective-c,ios,Iphone,Objective C,Ios,我有NSString draw功能,可以从文本创建UIImage,并将此图像与另一个UIImage以及可移动的UIImage组合。现在,我想将这两个UIImage组合成一个UIImage。查看UIGraphicsBeginImageContext和相关功能,这使您可以从和绘制中创建位图图像。您可以绘制文本和任何其他要创建新位图的内容。-(UIImage*)imageFromText:(NSString*)text -(UIImage *)imageFromText:(NSString *)tex

我有NSString draw功能,可以从文本创建UIImage,并将此图像与另一个UIImage以及可移动的UIImage组合。现在,我想将这两个UIImage组合成一个UIImage。

查看UIGraphicsBeginImageContext和相关功能,这使您可以从和绘制中创建位图图像。您可以绘制文本和任何其他要创建新位图的内容。

-(UIImage*)imageFromText:(NSString*)text
-(UIImage *)imageFromText:(NSString *)text
{
    // set the font type and size
    UIFont *font = [UIFont systemFontOfSize:20.0];
    CGSize size  = [text sizeWithFont:font];

    // check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+)
    if (UIGraphicsBeginImageContextWithOptions != NULL)
        UIGraphicsBeginImageContextWithOptions(size,NO,0.0);
    else
        // iOS is < 4.0
        UIGraphicsBeginImageContext(size);

    // optional: add a shadow, to avoid clipping the shadow you should make the context size bigger
    //
    // CGContextRef ctx = UIGraphicsGetCurrentContext();
    // CGContextSetShadowWithColor(ctx, CGSizeMake(1.0, 1.0), 5.0, [[UIColor grayColor] CGColor]);

    // draw in context, you can use also drawInRect:withFont:
    [text drawAtPoint:CGPointMake(0.0, 0.0) withFont:font];

    // transfer image
    UIImage *Image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return Image;
}
{ //设置字体类型和大小 UIFont*font=[UIFont systemFontOfSize:20.0]; CGSize size=[文本大小WithFont:font]; //检查UIGraphicsBeginImageContextWithOptions是否可用(iOS为4.0+) if(UIGraphicsBeginImageContextWithOptions!=NULL) UIGraphicsBeginImageContextWithOptions(大小,编号,0.0); 其他的 //iOS小于4.0 UIGraphicsBeginImageContext(大小); //可选:添加阴影,为避免剪切阴影,应使上下文大小更大 // //CGContextRef ctx=UIGraphicsGetCurrentContext(); //CGContextSetShadowWithColor(ctx、CGSizeMake(1.0、1.0)、5.0、[[UIColor grayColor]CGColor]); //在上下文中绘制,也可以使用drawInRect:withFont: [text drawAtPoint:CGPointMake(0.0,0.0)with font:font]; //转印图像 UIImage*Image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsSendImageContext(); 返回图像; }
在这里,我想到了将文本转换为图像的方法。

请正确提问。您尝试了什么,哪些有效,哪些无效?现在我想将此图像与另一个UIimage合并。我如何才能做到这一点?