0

我正在使用一个简单的裁剪UIImage,但是在我们检查最终图像进行裁剪后,它会在 iPhone 中旋转。下面是我用于裁剪的代码。

CGRect visibleRect;
float scale = 1.0f/scrollView.zoomScale;
visibleRect.origin.x = scrollView.contentOffset.x * scale;
visibleRect.origin.y = scrollView.contentOffset.y * scale;
visibleRect.size.width = scrollView.bounds.size.width * scale;
visibleRect.size.height = scrollView.bounds.size.height * scale;
finalImage = imageFromView(displayImageView.image, &visibleRect);

UIImage* imageFromView(UIImage* srcImage, CGRect* rect) {
    CGImageRef cr = CGImageCreateWithImageInRect(srcImage.CGImage, *rect);
    UIImage* cropped = [UIImage imageWithCGImage:cr];

    CGImageRelease(cr);
    return cropped;
}

如果我做错了什么,请告诉我。

4

1 回答 1

0

您需要在 crpping 后调用此方法

-(UIImage*)rotateImage:(UIImage*)image

{

UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0 , 0, image.size.width , image.size.height), [image CGImage]);


CGContextRotateCTM (context, radians(90));

CGImageRef cgImage = nil;

cgImage = CGBitmapContextCreateImage(context);

UIImage *img = [UIImage imageWithCGImage:cgImage];


return img;

}
于 2013-01-17T10:25:25.063 回答