Split UIImage in half?

后端 未结 3 1461
情书的邮戳
情书的邮戳 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 12:57

    You can try this,

    UIImage *image = [UIImage imageNamed:@"yourImage.png"];
    CGImageRef tmpImgRef = image.CGImage;
    CGImageRef topImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, 0, image.size.width, image.size.height / 2.0));
    UIImage *topImage = [UIImage imageWithCGImage:topImgRef];
    CGImageRelease(topImgRef);
    
    CGImageRef bottomImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, image.size.height / 2.0,  image.size.width, image.size.height / 2.0));
    UIImage *bottomImage = [UIImage imageWithCGImage:bottomImgRef];
    CGImageRelease(bottomImgRef);
    

    hope this can help you, :)

提交回复
热议问题