draw NSImage with CGContextDrawImage is too blurr

425 Views Asked by At

I draw my design image using CGContextDrawImage but its too blurry.

Please help me to improve its quality.

I am using this for drawing:

//NSImage* design_image

both sizes are same and i use this for interpolation

CGContextRef ct_ref=[context CGContext];
CGContextSetAllowsAntialiasing(ct_ref, YES);
CGContextSetShouldAntialias(ct_ref, YES);
CGContextSetInterpolationQuality(ct_ref, kCGInterpolationHigh);

id hints = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:NSImageInterpolationDefault] forKey:NSImageHintInterpolation];

CGImageRef img_ref=[design_image CGImageForProposedRect:&image_dr_rct context:context hints:hints];

CGContextDrawImage(ct_ref, CGRectMake(image_dr_rct.origin.x, image_dr_rct.origin.y, image_dr_rct.size.width, image_dr_rct.size.height), img_ref);
1

There are 1 best solutions below

2
Caleb On

If you're getting blurry results while drawing an image, the problem probably has to do with scaling the image. I can't tell from your question whether you're drawing the image larger or smaller than the original, but you can get poor results either way. You could try a different interpolation setting, like NSImageInterpolationHigh, but your best bet would be to create an original image at the size you need.