【问题标题】:draw NSImage with CGContextDrawImage is too blurr用 CGContextDrawImage 绘制 NSImage 太模糊
【发布时间】:2018-07-20 05:55:25
【问题描述】:

我使用 CGContextDrawImage 绘制我的设计图像,但它太模糊了。

请帮我提高它的质量。

我用这个来画画:

//NSImage* design_image

两个尺寸相同,我用它来插值

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

【问题讨论】:

    标签: objective-c image macos drawingcontext


    【解决方案1】:

    如果您在绘制图像时得到模糊的结果,问题可能与缩放图像有关。我无法从您的问题中判断您绘制的图像是比原始图像大还是小,但无论哪种方式,您都可以获得较差的结果。您可以尝试不同的插值设置,例如 NSImageInterpolationHigh,但最好的办法是创建所需大小的原始图像。

    【讨论】:

    • 两种尺寸相同,我用它来插值 CGContextRef ct_ref=[context CGContext]; CGContextSetAllowsAntialiasing(ct_ref, YES); CGContextSetShouldAntialias(ct_ref, YES); CGContextSetInterpolationQuality(ct_ref, kCGInterpolationHigh);
    • 抗锯齿会使边缘看起来有点模糊——你基本上是在用锐度换取平滑度。您还没有发布图片或模糊版本,因此很难真正知道您在说什么。
    猜你喜欢
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多