CGWindowListCreateImage在缩放时产生模糊的cgImage

时间:2017-02-19 19:21:18

标签: macos core-graphics retina-display nswindow zooming

我正在开发像mac应用程序这样的放大镜。我的目标是能够在放大时精确定位单个像素。我在mouseMoved中使用此代码(使用事件:NSEvent):

from nba_py import game, team
import pandas as pd
import numpy as np

# Constants
game_id = ['0021600849','0021600836']
tID = '1610612738'

bs = game.Boxscore(game_id=game_id[0], season='2016-17', season_type='Regular Season', range_type='0', start_period='0', end_period='0', start_range='0', end_range='0')
df_total = bs.player_stats()

df_total['TEAM_CITY'].values
df_total['TEAM_CITY'] = df_total['TEAM_CITY'=='Boston']

cgImage的创建发生在CGWindowListCreateImage方法中。当我稍后在NSView中绘制它时,结果如下所示:

enter image description here

它看起来模糊/像在创建cgImage期间应用了一些抗锯齿。我的目标是获得每个像素的锐利表示。谁能指出我正确的方向?

1 个答案:

答案 0 :(得分:2)

好的,我明白了。这是在绘图上下文中将插值质量设置为无的问题:

 context.interpolationQuality = .none

结果:

enter image description here

根据要求提供更多代码:

//get the context
guard let context = NSGraphicsContext.current()?.cgContext else { return }

//get the CGImage
let image: CGImage = //pass the result from CGWindowListCreateImage call

//draw
context.draw(image, in: (CGRect of choice))