Drawing a PNG Image Into a Graphics Context for Blending Mode Manipulation

前端 未结 1 1519
孤独总比滥情好
孤独总比滥情好 2020-12-14 04:48

I need to draw a series of PNGs into a CGContext so I can blend them together:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSe         


        
相关标签:
1条回答
  • 2020-12-14 05:21

    You don't need to be using UIImageViews. Instead, bracket your drawing between calls to UIGraphicsBeginImageContext and UIGraphicsEndImageContext.

    For example (code not tried):

    UIImage* uiimage = [UIImage imageNamed:@"image-name.png"];
    UIImage* uiimage2 = [UIImage imageNamed:@"other-image-name.png"];
    
    CGSize size = uiimage.size; 
    
    UIGraphicsBeginImageContext(size);
    
    [uiimage drawAtPoint:CGPointZero blendMode:kCGBlendModeOverlay alpha:1.0];
    [uiimage2 drawAtPoint:CGPointZero blendMode:kCGBlendModeOverlay alpha:1.0];
    
    UIImage* blendedImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    

    If you want to use CG calls, call:

    CGContextRef context = UIGraphicsGetCurrentContext();
    

    to get the context ref.

    0 讨论(0)
提交回复
热议问题