Split UIImage in half?

后端 未结 3 1462
情书的邮戳
情书的邮戳 2020-12-08 12:31

How would I go about splitting a UIImage In half(down the middle) so it would make two images?

3条回答
  •  被撕碎了的回忆
    2020-12-08 13:00

    - (void)splitImage:(UIImage *)image
    {
        CGFloat imgWidth = image.size.width/2;
        CGFloat imgheight = image.size.height;
    
        CGRect leftImgFrame = CGRectMake(0, 0, imgWidth, imgheight);
        CGRect rightImgFrame = CGRectMake(imgWidth, 0, imgWidth, imgheight);
    
        CGImageRef left = CGImageCreateWithImageInRect(image.CGImage, leftImgFrame);
        CGImageRef right = CGImageCreateWithImageInRect(image.CGImage, rightImgFrame);
    
        // These are the images we want!
        UIImage *leftImage = [UIImage imageWithCGImage:left];
        UIImage *rightImage = [UIImage imageWithCGImage:right];
    
        // Don't forget to free the memory!
        CGImageRelease(left);
        CGImageRelease(right);
    }
    

提交回复
热议问题