この質問について申し訳ありませんが、SO で多くのスレッドを検索しましたが、何も見つかりませんでした。
問題は、UIImage の中央の正方形をトリミングする方法です。
以下のコードを試しましたが、成功しませんでした。トリミングは行われますが、左上隅にあります。
-(UIImage*)imageCrop:(UIImage*)original
{
UIImage *ret = nil;
// This calculates the crop area.
float originalWidth = original.size.width;
float originalHeight = original.size.height;
float edge = fminf(originalWidth, originalHeight);
float posX = (originalWidth - edge) / 2.0f;
float posY = (originalHeight - edge) / 2.0f;
CGRect cropSquare = CGRectMake(posX, posY,
edge, edge);
// This performs the image cropping.
CGImageRef imageRef = CGImageCreateWithImageInRect([original CGImage], cropSquare);
ret = [UIImage imageWithCGImage:imageRef
scale:original.scale
orientation:original.imageOrientation];
CGImageRelease(imageRef);
return ret;
}