Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa Windows游标中的热点。NSImage加载的cur?_Cocoa_Nsimage_Nscursor - Fatal编程技术网

Cocoa Windows游标中的热点。NSImage加载的cur?

Cocoa Windows游标中的热点。NSImage加载的cur?,cocoa,nsimage,nscursor,Cocoa,Nsimage,Nscursor,根据Cocoa图像绘图指南,NSImage可以加载Windows游标.cur文件 但是如何获得NSCursor-initWithImage:(NSImage*)新图像热点:(NSPoint)点所需的热点?正如文档中所述 在OS X v10.4及更高版本中,NSImage使用映像I/O框架支持许多其他文件格式 所以,让我们在一个快速的操场上抓取和实验: import Foundation import ImageIO let url = Bundle.main.url(forResource:

根据Cocoa图像绘图指南,NSImage可以加载Windows游标.cur文件


但是如何获得NSCursor
-initWithImage:(NSImage*)新图像热点:(NSPoint)点所需的热点

正如文档中所述

在OS X v10.4及更高版本中,
NSImage
使用映像I/O框架支持许多其他文件格式

所以,让我们在一个快速的操场上抓取和实验:

import Foundation
import ImageIO

let url = Bundle.main.url(forResource: "BUSY_L", withExtension: "CUR")! as CFURL
let source = CGImageSourceCreateWithURL(url, nil)!
print(CGImageSourceCopyPropertiesAtIndex(source, 0, nil)!)
输出:

{
    ColorModel = RGB;
    Depth = 8;
    HasAlpha = 1;
    IsIndexed = 1;
    PixelHeight = 32;
    PixelWidth = 32;
    ProfileName = "sRGB IEC61966-2.1";
    hotspotX = 16;
    hotspotY = 16;
}
(16.0, 16.0)
因此,为了安全地获取热点:

import Foundation
import ImageIO

if let url = Bundle.main.url(forResource: "BUSY_L", withExtension: "CUR") as CFURL?,
    let source = CGImageSourceCreateWithURL(url, nil),
    let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [String: Any],
    let x = properties["hotspotX"] as? CGFloat,
    let y = properties["hotspotY"] as? CGFloat
{
    let hotspot = CGPoint(x: x, y: y)
    print(hotspot)
}
输出:

{
    ColorModel = RGB;
    Depth = 8;
    HasAlpha = 1;
    IsIndexed = 1;
    PixelHeight = 32;
    PixelWidth = 32;
    ProfileName = "sRGB IEC61966-2.1";
    hotspotX = 16;
    hotspotY = 16;
}
(16.0, 16.0)

谢谢你快速而彻底的回答。我应该写下我已经使用了CGImageSourceCopyPropertiesAtIndex,但在从
GCImage
移动到
NSImage
时,我希望使用另一种方法。因此,将
CGImageSourceCreateImageAtIndex
initWithCGImage
替换为
initWithContentsOfFile
没有意义。