UIImage 未正确拆分

UIImage Not Splitting Properly

我试图将 UIImage 水平分割成两半,保持图像的原始宽度,但返回的图像是原始图像的左上角。

CGImageRef imageRef = image.CGImage;

CGImageRef topR = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0,  image.size.width, image.size.height/2.0));
UIImage *topImage = [UIImage imageWithCGImage:topR];
CGImageRelease(topR);

当我将矩形设置为 (0,0, 1000, image.size.height/2) 时,它 returns 图像的整个宽度。我打印了 image.size.width 并且 returns 宽度正确,但是 createImageInRect 返回了顶角。

我改用了 CGImageGetWidth,现在可以用了

 CGImageRef topR = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)/2));