在 iOS 的颜色选择项目中放大图像时,如何防止像素变得模糊? [英] How to prevent the pixels from becoming blurry when I enlarge an image in my color pick project for iOS?

查看:28
本文介绍了在 iOS 的颜色选择项目中放大图像时,如何防止像素变得模糊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目,提供放大图像和从放大镜中选择像素颜色的能力,现在我可以放大图像的触摸位置,但放大镜显示的像素效果模糊,怎么办我让它一个一个的像素点显示的很清楚,没有任何模糊处理?

I'm making a little project that provides the ability to enlarge an image and pick pixels' colors from the magnifier, now I can magnify the touched place of the image, but the magnifier shows the pixels with blurry effect, how can I make it show the pixels one by one very clearly without any fuzzy processing?

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect bounds = self.bounds;
    CGImageRef mask = [UIImage imageNamed: @"loupe-mask@2x.png"].CGImage;
    UIImage *glass = [UIImage imageNamed: @"loupe-hi@2x.png"];

    CGContextSaveGState(context);
    CGContextClipToMask(context, bounds, mask);
    CGContextFillRect(context, bounds);
    CGContextScaleCTM(context, 40, 40);

    //draw your subject view here
    CGContextTranslateCTM(context,1*(self.frame.size.width*0.5),1*(self.frame.size.height*0.5));
    //CGContextScaleCTM(context, 1.5, 1.5);
    CGContextTranslateCTM(context,-1*(touchPoint.x),-1*(touchPoint.y));
    [self.viewToMagnify.layer renderInContext:context];

    CGContextRestoreGState(context);
    [glass drawInRect: bounds];
}

应该是:

不应该:

推荐答案

您想要设置缩放像素而不是插值的绘图模式.我认为对于您正在执行的绘图,您需要 CGContext 命令 CGContextSetInterpolationQuality,其值为 kCGInterpolationNone.

You want to set a drawing mode that scaled pixels rather than interpolating. I think for the drawing you're doing you want the CGContext command CGContextSetInterpolationQuality, with a value of kCGInterpolationNone.

(免责声明:我认为这就是设置,但我并不乐观,也没有尝试过.)

(Disclaimer: I think this is the setting, but I'm not positive, and haven't tried it.)

顺便说一句,最好避免在本网站上靠近 NSFW 的任何地方使用图像.这个网站在世界各地都有人阅读,我相信很多人在工作中阅读过它.不同的工作场所对可接受的标准有很大不同.您的示例图像非常危险.

BTW, it's probably best to avoid images that anywhere close to NSFW on this site. This site is read all over the world, and I'm sure plenty of people read it at work. Different workplaces have widely different standards of what's acceptable. Your sample image is pretty risqué.

这篇关于在 iOS 的颜色选择项目中放大图像时,如何防止像素变得模糊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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