Create a UIImage from two other UIImages on the iPhone

后端 未结 3 1513
一生所求
一生所求 2020-12-07 16:03

I\'m trying to write an animation on the iPhone, without much success, getting crashes and nothing seems to work.

What I wanna do appears simple, create a UIImage, a

3条回答
  •  爱一瞬间的悲伤
    2020-12-07 16:38

    Here is an example to merge two images that are the same size into one. I don't know if this is the best and don't know if this kind of code is posted somewhere else. Here is my two cents.

    + (UIImage *)mergeBackImage:(UIImage *)backImage withFrontImage:(UIImage *)frontImage
    {
    
        UIImage *newImage;
    
        CGRect rect = CGRectMake(0, 0, backImage.size.width, backImage.size.height);
    
        // Begin context
        UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
    
        // draw images
        [backImage drawInRect:rect];
        [frontImage drawInRect:rect];
    
        // grab context
        newImage = UIGraphicsGetImageFromCurrentImageContext();
    
        // end context
        UIGraphicsEndImageContext();
    
        return newImage;
    }
    

    Hope this helps.

提交回复
热议问题