gpt4 book ai didi

objective-c - 从 NSProgressIndicator 获取 NSImage

转载 作者:太空狗 更新时间:2023-10-30 03:51:05 33 4
gpt4 key购买 nike

我需要将 NSProgressIndicator 中的图像放入 NSOutlineView 单元格中。我已经编写了针对确定指标执行此操作的代码,并且效果很好:

NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:NO];
[progressIndicator setMaxValue:100.0];
[progressIndicator setDoubleValue:somePercentage];

NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];


return [updateImage autorelease];

我已尝试修改代码以提供不确定的指示器图像。但是对于不确定的情况,我总是得到一张空白的 16x16 图像。 (我已经通过在每种情况下将图像写入文件来确认这一点,确定的情况给我进度指示器图像,不确定的情况始终是 16x16 白色方 block )。

修改后的代码为:

if(self.lengthUnknown)
{
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:YES];

NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];


return [updateImage autorelease];
}
else
{
// Same code as the first listing, this case works fine
}

不确定的进度指示器是否使用某种导致 -dataWithPDFInsideRect: 无法捕获其图像的绘图类型?


更多信息:我尝试将进度指示器设置为不使用线程动画,并尝试按照下面的建议通过 NSImage 的 lockFocus 方法获取内容,但这些尝试都没有效果。

Dave 在下面提到的进度指示器单元格代码 (AMIndeterminateProgressIndicatorCell) 是一个很好的解决方法,但我仍然想知道为什么我不能使用与确定模式相同的技术。

最佳答案

我用过 AMIndeterminateProgressIndicatorCell用于细胞中不确定的进度指标。它不是真正的 NSProgressIndicator,因为它是自己绘制的,但它是一个非常好的复制品,IMO。

alt text
(来源:harmless.de)

关于objective-c - 从 NSProgressIndicator 获取 NSImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/262407/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com