当添加贴纸时,来自CgImageRef的UIImage


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];

但是我没有得到图像。知道为什么吗?非常感谢任何帮助。

我注意到你的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

相关内容

  • 没有找到相关文章

最新更新