我正在尝试将超过 1 个带有背景图像的图像保存到单个图像中,然后将其保存出来。我发现了如何拼合图像,但是我在背景顶部添加的图像在拼合它们时没有出现在正确的位置。似乎它们以不同的背景图像大小出现在不同的位置。
UIGraphicsBeginImageContext(backGroundImage.image.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//CGRect area= [self bounds];
CGRect area = CGRectMake(0, 0, backGroundImage.image.size.width, backGroundImage.image.size.height);
CGRect area2= CGRectMake(testImage.frame.origin.x, testImage.frame.origin.y, testImage.frame.size.width, testImage.frame.size.height);
//Need to flip images to the correct orientation
CGContextTranslateCTM(ctx, 0, area.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
//Drawing background first
CGContextDrawImage(ctx, area, backGroundImage.image.CGImage);
//Draw other images on top
//[[AccessoryManager sharedManager] SaveImages:ctx];
CGContextDrawImage(ctx, area2, testImage.image.CGImage);
//Creating one single image from context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum( newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil );