Ios 将UIImage导出为可拉伸图像导出图像,并在图像上绘制水平线和垂直线

Ios 将UIImage导出为可拉伸图像导出图像,并在图像上绘制水平线和垂直线,ios,uiimage,Ios,Uiimage,我试图建立一个应用程序,它结合了一个背景图像和文本气泡的顶部。我将文本气泡初始化为可拉伸的UIImage,并定义了leftCapWidth和topCapHeight。在应用程序中显示文本气泡时,一切正常,文本气泡显示正常,上面没有任何线条 但是,当我尝试导出图像时,我使用UIGraphicsBeginImageContext()函数将背景图像与顶部的文本气泡组合起来,我看到文本气泡上绘制了一条垂直线和一条水平线。它们似乎是在leftCapWidth和topCapHeight定义的点上绘制的。以前

我试图建立一个应用程序,它结合了一个背景图像和文本气泡的顶部。我将文本气泡初始化为可拉伸的UIImage,并定义了leftCapWidth和topCapHeight。在应用程序中显示文本气泡时,一切正常,文本气泡显示正常,上面没有任何线条

但是,当我尝试导出图像时,我使用UIGraphicsBeginImageContext()函数将背景图像与顶部的文本气泡组合起来,我看到文本气泡上绘制了一条垂直线和一条水平线。它们似乎是在leftCapWidth和topCapHeight定义的点上绘制的。以前有人遇到过这样的问题吗

我在应用程序中渲染图像和导出图像时看到的唯一区别是,我使用UIImageView保存可拉伸图像,而导出时我只使用UIImages

用于将气泡图像组合到背景图像的代码:

UIGraphicsBeginImageContext(mainImage.size);

[fullSectionImage drawInRect:CGRectMake(0, 0, mainImage.size.width, mainImage.size.height) blendMode:kCGBlendModeNormal alpha:1.0 ];

UIImage *bubbleImage = [UIImage imageNamed:@"bubble1.png"];
stretchableImage = [bubbleImage stretchableImageWithLeftCapWidth:40 topCapHeight:15];
[stretchableImage drawInRect:CGRectMake(originX,originY,width,height) blendMode: kCGBlendModeNormal alpha:1.0 ];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();   
UIImageWriteToSavedPhotosAlbum(newImage, nil,nil,nil);
用于在应用程序中显示与背景图像相同的气泡的代码:

UIImageView *bubbleImageView;
UIImage *bubbleImage = [UIImage imageNamed:@"bubble1.png"];
stretchableImage = [bubbleImage stretchableImageWithLeftCapWidth:40 topCapHeight:15];
bubbleImageView = [[UIImageView alloc] initWithImage:stretchableImage];
[bubbleImageView setFrame:CGRectMake(0,0,width,height)];
bubbleImageView.autoresizingMask = YES;
[self addSubview:bubbleImageView];

为了解决这个问题,StretcableImage应该使用drawInRect方法,将所有整数值作为参数

[stretchableImage drawInRect:CGRectMake(originX,originY,width,height) blendMode: kCGBlendModeNormal alpha:1.0 ];

在这种情况下,originX、originY、width和height需要为整数值。这为我解决了这个问题。

如果您可以添加一个屏幕截图(导出的坏图像)也会很有帮助。堆栈溢出不允许我添加图片。我已经在指定的链接上传了。有人吗?您是否可以显示创建可拉伸图像的代码,以便我们可以确切地看到您定义的大写字母?信息越多,帮助就越容易。使用
UIGraphicsBeginImageContext()
的代码也不会影响查看。添加了代码块。希望有帮助。