UIImage在iPhone中裁剪后显示模糊 [英] UIImage showing blur after cropping in iPhone

查看:204
本文介绍了UIImage在iPhone中裁剪后显示模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序上有一个uiscrollview并具有uiviewview子视图,当用户单击库中显示在该图像视图上的任何照片时,用户可以移动,缩放和缩放图像,当用户单击裁剪"按钮时,应裁剪该图像在imageview中的部分中,在iPhone 3GS中其工作正常,但是在视网膜中,其不能正确进行裁剪显示了不同的图像.

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

推荐答案

帧大小不代表物理像素. 因此,如果您使用的是视网膜,请进行以下更改.

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);

其他事情都没事.

这篇关于UIImage在iPhone中裁剪后显示模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆