Это то, что я пытаюсь сделать: создайте два слоя CGLayers, A и B. Поместите B над A, используя режим наложения, получите получившееся изображение.
Это код
// Begin the drawing
CGLayerRef objectLayer;
CGContextRef fundoContext, objectContext;
CGRect backRect, objectRect;
CGFloat w = myImage.size.width;
CGFloat h = myImage.size.height;
CGSize sz = CGSizeMake(w, h);
backRect = CGRectMake (0, 0, h, w);
UIGraphicsBeginImageContext(sz);
CGContextRef context = UIGraphicsGetCurrentContext();
fundoLayer = CGLayerCreateWithContext (context, sz, NULL);
fundoContext = CGLayerGetContext (fundoLayer);
CGContextDrawImage(fundoContext, backRect, myImage.CGImage);
CGContextDrawLayerAtPoint(context, CGPointMake(0,0), fundoLayer);
UIImage *myObject = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"image" ofType:@"png"]];
w = myObject.size.width;
h = myObject.size.height;
sz = CGSizeMake(w, h);
float centroW, centroH;
// centering
objectRect = CGRectMake (((myImage.size.width - w) / 2 ),
((myImage.size.height - h) / 2 ), w, h);
centroW = myImage.size.width / 2;
centroH = myImage.size.height / 2;
//objectRect = CGRectMake (0, 0, h, h);
objectLayer = CGLayerCreateWithContext (context, sz, NULL);
objectContext = CGLayerGetContext (objectLayer);
// in theory this should set the blendmode of the top layer to screen…
CGContextSetBlendMode(objectContext, kCGBlendModeScreen);
CGContextDrawImage(objectContext, objectRect, myObject.CGImage);
CGContextDrawLayerAtPoint(context, CGPointMake(centroW, centroH), objectLayer);
resultingImage = UIGraphicsGetImageFromCurrentImageContext();
результат, который я получаю, состоит в том, что resultImage не равен композиции двух слоев. На самом деле resultImage равен только первому слою. Второй слой игнорируется этим !!!
???
я что-то упустил?
спасибо за любую помощь.