0
UIImage *sticky = [UIImage imageNamed:@"Radio.png"];
[_imgViewSticky setImage:sticky];
CIImage *outputImage = [self.originalImage CIImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImg = [context createCGImage:outputImage fromRect:[outputImage extent]];
float widthRatio = [outputImage extent].size.width / 320;
float heighRatio = [outputImage extent].size.height / 480;
CGPoint cgStickyPoint = CGPointMake(_imgViewSticky.frame.origin.x * widthRatio, _imgViewSticky.frame.origin.y * heighRatio);

cgImg = [self setStickyForCGImage:cgImg withPosition:cgStickyPoint];

最后一行返回一个 CGImageRef 对象。

我将值分配给最终图像,如下所示:

UIImage *finalImage = [UIImage ImageWithCGImageRef:cgImg];

但是我没有得到图像。任何想法为什么?任何帮助深表感谢。

4

1 回答 1

3

我注意到您的 CIContext 没有收到任何绘图,这可能是您没有获得图像的原因。我不清楚你想要什么,但这段代码会将一个 UIImage 叠加在另一个 UIImage 之上:

UIGraphicsBeginImageContextWithOptions(backgroundImage.size, NO, 0.0); //Create an image context
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)]; //Draw the first UIImage
[stickerImage drawInRect:stickerRect]; //Draw the second UIImage wherever you want on top of the first image
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext(); //Get the final UIImage result
于 2013-03-12T02:51:04.077 回答