【问题标题】:UIImage from CgImageRef while adding sticker添加贴纸时来自 CgImageRef 的 UIImage
【发布时间】:2013-03-12 19:46:02
【问题描述】:
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];

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

【问题讨论】:

  • 您能描述一下您想要实现的目标吗?我认为应该有更简单的方法来做到这一点。
  • 我正在尝试将贴纸添加到图像中。非常像 Aviary,只有我的应该使用 2 个手指手势

标签: ios uiimage core-image ciimage


【解决方案1】:

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

【讨论】:

  • 感谢工作!我被击中了一秒钟,但一切都很好。
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2020-09-21
  • 2015-10-22
  • 1970-01-01
  • 1970-01-01
  • 2020-06-17
  • 1970-01-01
相关资源
最近更新 更多