问题
I my app, i have one uiscrollview and have subview uiimageview on it, when user clicks any photo from library it display on that imageview, user can move,zoom and scale the image, when user clicks crops button it should crop that part which is in imageview, in iPhone 3GS its working perfectly fine, however in retina it not working correctly cropping is showing different image.
- (UIImage *)currentSlice {
CGSize sliceSize = imageView.frame.size;
UIGraphicsBeginImageContextWithOptions(sliceSize, NO, 0.0);
[imageView.image drawInRect:CGRectMake(0, 0, sliceSize.width, sliceSize.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGRect sliceRect = CGRectMake(scrollView.contentOffset.x, scrollView.contentOffset.y, scrollView.frame.size.width, scrollView.frame.size.height);
CGImageRef imageSlice = CGImageCreateWithImageInRect(scaledImage.CGImage, sliceRect);
return [UIImage imageWithCGImage:imageSlice];
}
i have used this method for cropping, please help me with this issue
回答1:
Frame size does not represent physical pixel. So, if you are working with retina do below change.
CGSize sliceSize = CGSizeMake(imageView.frame.size.width * 2.0, imageView.frame.size.height * 2.0);
CGRect sliceRect = CGRectMake(scrollView.contentOffset.x, scrollView.contentOffset.y, scrollView.frame.size.width * 2.0, scrollView.frame.size.height * 2.0);
Rest of the things are fine.
来源:https://stackoverflow.com/questions/12109519/uiimage-showing-blur-after-cropping-in-iphone