gpt4 book ai didi

iphone - 在 iPhone 中将两张图像合并为一张图像

转载 作者:行者123 更新时间:2023-12-03 20:52:15 25 4
gpt4 key购买 nike

我需要将两个图像合并为一个图像,这是我的代码:

-(UIImage*)mergeImage:(UIImage*)mask overImage:(UIImage*)source inSize:(CGSize)size
{
//Capture image context ref

UIImageView *totalimage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

UIImageView *firstImage=[[UIImageView alloc] initWithImage:mask];
UIImageView *secondImage=[[UIImageView alloc] initWithImage:source];

[totalimage addSubview:firstImage];
[totalimage addSubview:secondImage];

UIGraphicsBeginImageContext(totalimage.bounds.size);
[totalimage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Draw images onto the context
[source drawInRect:CGRectMake(0, 0, source.size.width, source.size.height)];
[mask drawInRect:CGRectMake(0, 0, mask.size.width, mask.size.height)];

return viewImage;

}

我按如下方式调用此方法:

UIImage *totalImage = [self mergeImage:self.Apicimage overImage:questionImage inSize:CGSizeMake(100, 100)];

但在执行时我得到以下输出:

Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSaveGState: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetBlendMode: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetAlpha: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextTranslateCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextScaleCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextConcatCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextDrawImage: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextRestoreGState: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSaveGState: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetBlendMode: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetAlpha: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextTranslateCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextScaleCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextConcatCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextDrawImage: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextRestoreGState: invalid context 0x0

有人可以指导我吗?如何合并两个图像?

最佳答案

你的代码

[source drawInRect:CGRectMake(0, 0, source.size.width, source.size.height)]; 
[mask drawInRect:CGRectMake(0, 0, mask.size.width, mask.size.height)];

应该写在

之前
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

关于iphone - 在 iPhone 中将两张图像合并为一张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com