Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

objective c - How to prevent the pixels from becoming blurry when I enlarge an image in my color pick project for 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];
}

Should be:

enter image description here

Should not be:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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é.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...