我在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;
}
如果我做了任何错误的事,请告诉我。
答案 0 :(得分:0)
您需要在压缩后调用此方法
-(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;
}