ios – 将UIImage分成两半?

前端之家收集整理的这篇文章主要介绍了ios – 将UIImage分成两半?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我怎样才能将UI Image分成两半(从中间开始),这样就会产生两个图像?

解决方法

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

CGImageRef bottomImgRef = CGImageCreateWithImageInRect(tmpImgRef,image.size.height / 2.0,image.size.height / 2.0));
UIImage *bottomImage = [UIImage imageWithCGImage:bottomImgRef];
CGImageRelease(bottomImgRef);

希望这可以帮到你,:)

猜你在找的iOS相关文章