- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试以编程方式创建 ICNS(包括 1024x1024 图像)。目前我正在创建一个 NSImage
,然后创建具有适当分辨率的 CGImageRef
对象,最后我使用 CGImageDestinationAddImage()< 将它们添加到图标中
。 Peter Hosey 已经帮助我创建了“@2x”图像,但不想设置图像的大小。
这是代码(还是有点乱,sourcefile
代表图像的路径):
NSSize sizes[10];
sizes[0] = NSMakeSize(1024,1024);
sizes[1] = NSMakeSize(512,512);
sizes[2] = NSMakeSize(512,512);
sizes[3] = NSMakeSize(256,256);
sizes[4] = NSMakeSize(256,256);
sizes[5] = NSMakeSize(128,128);
sizes[6] = NSMakeSize(64,64);
sizes[7] = NSMakeSize(32,32);
sizes[8] = NSMakeSize(32,32);
sizes[9] = NSMakeSize(16,16);
int count = 0;
for (int i=0 ; i<10 ; i++) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"Size%i",i+1]]) count++;
}
NSURL *fileURL = [NSURL fileURLWithPath:aPath];
// Create icns
CGImageDestinationRef dr = CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeAppleICNS , count, NULL);
NSImage *img = [[NSImage alloc] initWithContentsOfFile:sourcefile];
for (int i=0 ; i<10 ; i++) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"Size%i",i+1]]) {
// Create dictionary
BOOL is2X = true;
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 9) is2X = false;
int dpi = 144, size = (int)(sizes[i].width/2);
if (!is2X) {dpi = 72;size = sizes[i].width;}
[img setSize:NSMakeSize(size,size)];
for (NSImageRep *rep in [img representations])[rep setSize:NSMakeSize(size,size)];
const void *keys[2] = {kCGImagePropertyDPIWidth, kCGImagePropertyDPIHeight};
const void *values[2] = {CFNumberCreate(0, kCFNumberSInt32Type, &dpi), CFNumberCreate(0, kCFNumberSInt32Type, &dpi)};
CFDictionaryRef imgprops = CFDictionaryCreate(NULL, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// Add image
NSRect prect = NSMakeRect(0,0,size,size);
CGImageRef i1 = [img CGImageForProposedRect:&prect context:nil hints:nil];
CGImageDestinationAddImage(dr, i1, imgprops);
}
}
CGImageDestinationFinalize(dr);
CFRelease(dr);
size
是当前图像应有的宽度或高度。如果我们制作“@2x”图像,dpi
为 144,否则为 72。这些值已使用 NSLog
检查。
生成的 ICNS 文件中的图像与输入图像的大小相同。如果输入图像的大小是 1024x1024,ImageIO 会提示:
ImageIO: _CGImagePluginWriteICNS unsupported image size (1024 x 1024) - scaling factor: 1
每次dpi为72、尺寸为1024x1024时,都会出现上述错误。
我需要知道如何设置要添加到 ICNS 文件中的 CGImage 的大小。
<小时/>编辑:我记录了图像:
2012-12-31 12:48:51.281 Eicon[912:680f] |NSImage 0x101b4caf0 Size={512, 512} Reps=(
"NSBitmapImageRep 0x10380b900 Size={512, 512} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=1024x1024 Alpha=YES
Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.058 Eicon[912:680f] |NSImage 0x101b4caf0 Size={512, 512} Reps=(
"NSBitmapImageRep 0x10380b900 Size={512, 512} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO
Format=2 CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.111 Eicon[912:680f] |NSImage 0x101b4caf0 Size={256, 256} Reps=(
"NSBitmapImageRep 0x10380b900 Size={256, 256} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO
Format=2 CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.238 Eicon[912:680f] |NSImage 0x101b4caf0 Size={256, 256} Reps=(
"NSBitmapImageRep 0x10380b900 Size={256, 256} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO
Format=2 CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.309 Eicon[912:680f] |NSImage 0x101b4caf0 Size={128, 128} Reps=(
"NSBitmapImageRep 0x10380b900 Size={128, 128} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO
Format=2 CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.409 Eicon[912:680f] |NSImage 0x101b4caf0 Size={128, 128} Reps=(
"NSBitmapImageRep 0x10380b900 Size={128, 128} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO
Format=2 CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.534 Eicon[912:680f] |NSImage 0x101b4caf0 Size={32, 32} Reps=(
"NSBitmapImageRep 0x10380b900 Size={32, 32} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO Format=2
CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.616 Eicon[912:680f] |NSImage 0x101b4caf0 Size={32, 32} Reps=(
"NSBitmapImageRep 0x10380b900 Size={32, 32} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO Format=2
CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.729 Eicon[912:680f] |NSImage 0x101b4caf0 Size={16, 16} Reps=(
"NSBitmapImageRep 0x10380b900 Size={16, 16} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO Format=2
CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
2012-12-31 12:48:52.864 Eicon[912:680f] |NSImage 0x101b4caf0 Size={16, 16} Reps=(
"NSBitmapImageRep 0x10380b900 Size={16, 16} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=1024x1024 Alpha=YES Planar=NO Format=2
CurrentBacking=|CGImageRef: 0x101c14630| CGImageSource=0x10380ae70"
)|
最佳答案
错误信息是正确的。您所放入的图像尺寸不受 IconFamily 格式的支持。具体来说,从您的输出来看:
2012-12-26 13:48:57.682 Eicon[1131:1b0f] |NSImage 0x1025233b0 Size={11.52, 11.52} Reps=( "NSBitmapImageRep 0x10421fc30 Size={11.52, 11.52} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=1024x1024 Alpha=NO Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x104221170"
11.52 磅对于 IconFamily 的任何元素都不是有效的大小。您需要找出为什么此图像和代表具有该尺寸。
其他一些事情:
大小
(点大小)(最好是有效的值)。-[NSImage initWithSize:]
文档说:
It is permissible to initialize the receiver by passing a size of (0.0, 0.0); however, the receiver’s size must be set to a non-zero value before the NSImage object is used or an exception will be raised.
您没有设置任何一个对象的大小,而这是您需要做的。 (我很惊讶你没有像文档 promise 的那样得到异常(exception)。)
正如我在您的另一个问题中提到的,不再有 1024 点元素了; 1024 x 1024 像素元素的正确规范是 512 点 @ 2x。这是 (NSSize){ 512.0, 512.0 }
(点)的大小
(图像和代表),代表为 1024 pixelsWide
和 1024 pixelsHigh
。
看来我之前错过了一个关键成分。在这里。
您提供给 CGImageDestination 的 CGImage 没有与之关联的点大小 - 只有 NSImages 和 NSImageReps 有该点大小。 CGImage 只有像素大小;没有任何内容表明图像的物理尺寸或分辨率。
要告诉 CGImageDestination 给定的 CGImage 是 @ 1x 还是 @ 2x,您需要创建一个给出图像 DPI 的字典:
NSDictionary *imageProps1x = @{
(__bridge NSString *)kCGImagePropertyDPIWidth: @72.0,
(__bridge NSString *)kCGImagePropertyDPIHeight: @72.0,
};
NSDictionary *imageProps2x = @{
(__bridge NSString *)kCGImagePropertyDPIWidth: @144.0,
(__bridge NSString *)kCGImagePropertyDPIHeight: @144.0,
};
将正确的字典作为最后一个参数传递给CGImageDestinationAddImage
。
关于macos - 以编程方式创建 ICNS : "Unsupported Image Size",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14085843/
Apple M1 芯片上的 Mac OS 11.6 节点版本是17.0.1 % node -v v17.0.1 这个错误似乎真的来 self 无法辨别的任何地方。 (我检查了我的软件更新,没有最近的操
运行 cv2.getRectSubPix(img, (5,5), (0,0)) 抛出错误: OpenCV Error: Unsupported format or combination of for
不可能在 itunesconnect 中发送应用程序的新版本。虽然上周,同样的版本发送发生了。在代码中,我只是改了一个按钮的名字,没有再改哪里。 但总是报错: 错误 ITMS-9000:“不支持的架构
鉴于下面的 HTML,我尝试使用 jQuery 来匹配所有具有类“foo”的跨度的列表项,并且该跨度应包含文本“relevant”。 Some text relevant Some more
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
尝试安装friday软件包时,出现错误 Preprocessing library friday-0.2.2.0... src/Vision/Detector/Edge.hs:3:14: Unsupp
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
我的代码抛出此错误 Failed to load resource: unsupported url在以下行: self.$el.find('.capturedImage').attr('src',
首先,请原谅它已经被问过或者可以很容易地通过谷歌找到。我发布这个是因为我的时间有限。这是录制音频和视频的代码。 stopPreview(); Log.d("stream
我正在尝试在 Android 上实现应用索引。 我有一个 Intent 过滤器,如下:
对于在 WAS 8.5 中运行的应用程序客户端,我们有代码创建套接字失败并出现以下错误。 SSLSocketFactory factory = (SSLSocketFactory) SSLSo
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我正在尝试从序列中获取生成的 key 。(使用 Servlet 和 Oracle10) 以下是我的代码: query ="insert into TABLE_NAME(COL1,COL2,COL3)
我的项目中有这个功能: def clean(self): if self.id_document_type == 'BC': now = date.today()
我在尝试 ARKit 时出现黑屏并显示以下错误消息。 WWDC 2017 示例 PlacingObjects 在同一设备上运行没有问题。 [] >>> FigVirtualFramebufferGet
ffmpeg 缺乏对 AAC 的默认支持真的很烦人: 我的 ffmpeg 版本: ffmpeg version git-2020-05-02-0d81edc Copyright (c) 2000-20
以下 config.xml 导致错误: ... ... ... 错误信息: Error Image 代码库是继承的,据我所知
创建位图上下文时出现此错误: CGBitmapContextCreate:不支持的参数组合:8 个整数位/组件; 24 位/像素;三分量色彩空间; kCGImageAlphaNone; 7936 字节
使用 pandas 读取 .xlsx 文件时出错。看起来它正在打开文件,因为它能够读取列名的前 8 个字符,即 员工编号 但因此错误而失败。我看到很多关于这个的帖子,但最后一部分从来都不是这些错误
我尝试执行下面的代码,但它抛出以下错误消息: Error: Syntax error, unrecognized expression: unsupported pseudo: really-good
我是一名优秀的程序员,十分优秀!