2013-03-12 43 views
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对象。从CgImageRef UIImage添加贴纸

而且我这样分配值到最终图像:

UIImage *finalImage = [UIImage ImageWithCGImageRef:cgImg];

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

+0

你可以描述一下你想实现什么吗?我认为应该有更简单的方法来做到这一点。 – 2013-03-12 01:22:33

+0

我正在尝试将贴纸添加到图像。非常像百鸟园,只有我的应该使用2个手指手势 – CalZone 2013-03-12 02:15:31

回答

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 
+0

谢谢你的工作!我被打了一秒钟,但它的一切都很好。 – CalZone 2013-03-12 20:44:15