我将转换应用于UIImageView(旋转,缩放和反转),我想从旋转的UIImageView中保存UIImage。那么如何才能获得UIImage的精确边界框来绘制UIImage视图。
CGAffineTransform transform = selImageView.transform;
CGPathRef rotatedImageRectPath = CGPathCreateWithRect(selImageView.frame, &transform);
CGRect boundingBox = CGPathGetBoundingBox(rotatedImageRectPath);
CGSize rotatedSize = boundingBox.size;
UIGraphicsBeginImageContextWithOptions(rotatedSize, NO, 0.0f);
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), rotatedSize.width/2, rotatedSize.height/2);
// CGContextSetFillColorWithColor(UIGraphicsGetCurrentContex(),[UIColor clearColor].CGColor);
//Rotate the image context using tranform
CGContextConcatCTM(UIGraphicsGetCurrentContext(), selImageView.transform);
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(-aTransImage.size.width / 2, -aTransImage.size.height / 2, aTransImage.size.width, aTransImage.size.height), [aTransImage CGImage]);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;