我正在尝试向OSX中的图像文件添加TIFF字典。
From Apple's documentation,看起来kCGImagePropertyTIFFDictionary
定义了一个字典,字典中有kCGImagePropertyTIFFXResolution
这样的键。你知道吗
我不知道如何在我的python代码中实现它。目前,我刚把这本词典作为一把钥匙和其他钥匙放在一起。(因此它不会将任何键设置到文件中。) 这是我的密码:
options = {
kCGImagePropertyTIFFDictionary: 'TIFFDictionary',
kCGImagePropertyTIFFXResolution: "300",
kCGImagePropertyTIFFYResolution: "300",
kCGImagePropertyTIFFResolutionUnit: 2
}
CGImageDestinationAddImage(destination, image, options)
CGImageDestinationSetProperties(destination, options)
下面是来自open source script的一些其他python代码,可能可以工作,但我不明白它在做什么。你知道吗
imageProps = CGImageSourceCopyPropertiesAtIndex(imageSrc, 0, None)
if imageProps is not None :
tiffProps = imageProps[kCGImagePropertyTIFFDictionary]
if tiffProps is not None :
xRes = tiffProps[kCGImagePropertyTIFFXResolution]
yRes = tiffProps[kCGImagePropertyTIFFYResolution]
结果是需要嵌套字典。另一个问题是数字必须是数字,这并不奇怪。你知道吗
一个更好的解决方案是根本不使用TIFF字典,因此它可以用于其他文件格式:
相关问题 更多 >
编程相关推荐