14
Bu soru için üzgünüm, fakat burada S.O. ve hiçbir şey bulamadım.UIImage'da merkez karesi nasıl kırpılır?
Soru şudur: UIImage'da bir orta kareyi nasıl kırpılır?
Kod feryatını denedim ama başarılı olamadım. Kırpma işlemi gerçekleşir, ancak sol üst köşede.
-(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;
}