所以这就是我到目前为止所做的。我正在使用从相机捕获的 UIImage,并且可以在横向时裁剪中心正方形。由于某种原因,这并没有像预期的那样转换为纵向模式。我将发布我的代码和日志仅供参考。
代码:
CGRect squareRect = CGRectMake(offsetX, offsetY, newWidth, newHeight);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], squareRect);
image = [UIImage imageWithCGImage:imageRef scale:1 orientation:image.imageOrientation];
纵向结果(非方形):
original image size: {1536, 2048}, with orientation: 3
squareRect: {{0, 256}, {1536, 1536}}
new image size: {1280, 1536}, with orientation: 3 <--- not expected
景观结果(正方形):
original image size: {2048, 1536}, with orientation: 1
squareRect: {{256, 0}, {1536, 1536}}
new image size: {1536, 1536}, with orientation: 1
这是 CGImageCreateWithImageInRect() 中的错误还是我在这里遗漏了什么?