objective-c - 使用 Objective-C 访问 .heic 图像文件的深色版本
问题描述
在 MacOS 上,.heic 图像文件可以包含一个浅色和一个深色版本。这可以通过系统壁纸看到open
:例如
open /System/Library/Desktop\ Pictures/Dome.heic
预览应用程序显示两个版本。我的目标是能够使用 Objective-C 访问它们,因为我想将浅色和深色版本都保存为 .jpg 格式。
以下代码段成功提取了轻量版本并将其保存到磁盘:
NSString* wallpaper_path = /* insert source path here */;
NSString* converted_path_str = /* insert destination path here */;
NSImage* image = [[[NSImage alloc] initWithContentsOfFile:wallpaper_path] autorelease];
NSData* data = [image TIFFRepresentation];
NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:data];
NSDictionary* properties =[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
data = [rep representationUsingType:NSJPEGFileType properties:properties];
[data writeToFile:converted_path_str atomically:NO];
但是我找不到如何使用NSImage
,NSImageRep
或NSBitmapImageRep
. 由于预览成功地做到了,我认为这是可能的。我只是不知道该怎么做。
解决方案
推荐阅读
- node.js - Nodejs的多个发布请求
- node.js - 当我在 node.js 中运行 npm start 时如何解决此错误
- python - 如何使用 Python 和 Flask 摆脱 500 内部服务器错误?
- containers - 适用于多种服务的 AWS 负载均衡器
- javascript - 如何创建一个在 HTML 中打开文件夹和文件的搜索框?
- python-3.7 - Python 3,不支持的操作数类型 -: 'str' 和 'str'
- python - Python循环性能问题
- javascript - 为什么创建游戏动画序列的 while 循环似乎被忽略了?
- c++ - 在这个 test() 中发生了什么意外的过程?为什么总是覆盖 ch[0 1 2...]?
- python - IF, ELIF, ELSE ArcPro 如何计算一个字段