UIImage showing blur after cropping in iPhone

[亡魂溺海] 提交于 2019-12-11 15:26:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!