Good day all;
I am trying to manually (not using sublayers) draw images within a CATiledLayer but it is not behaving as it should with the defined solution. I undertand that when you call 'CGContextDrawImage' you must scale and translate so as to flip it but I cannot for the life of me, get it to work.
I have a method called
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image
which is called several times from with in
- (void)drawInContext:(CGContextRef)context
to render all the images that go into the CATileLayer.
The following renders no images:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, image.CGImage);
CGContextRestoreGState(context);
The following produces an image but rendered incorrectly:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextDrawImage(context, rect, image.CGImage);
Like wise with this:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, image.CGImage);
I have also tried:
UIGraphicsBeginImageContext
UIGraphicsEndImageContext
and
UIGraphicsPushContext
UIGraphicsPopContext
All do not work. I am missing something fundamental here and I suspect my approach to saving the contexts is not working.