Getting NSImage from CGImageRef

末鹿安然 提交于 2019-12-03 22:14:32

The matching method in NSImage is initWithCGImage:size:.

The second argument takes the image's size in points. The factor between the size in pixels (of the CGImage) and the size in points is the scale factor. So, for example, if you have a 100×100px CGImage, and pass a size of (NSSize){ 50.0, 50.0 }, the image will be 50 points in size, and double-resolution.

Usually you should just pass the size in pixels (from the CGImage) as the size in points. For handling multiple scale factors, it's better to use a single NSImage with multiple NSImageReps, like what you get from -[NSWorkspace iconForFileType:] for most types or from creating an NSImage from a typical .icns file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!