从 QCView 拍摄的快照有时为空白
我有一个在 QCViews 中播放石英乐曲的程序。 因为 QCView 位于辅助屏幕上,所以我需要在主屏幕(一种控制屏幕)中显示一个(较小的)副本。
因此,我每 0.1 秒触发一个计时器,拍摄 QCView 的快照,并将生成的图像设置在 NSImageView 中。
我的问题:
快照大约 90% 的时间都是正确的,但有时会变成空白。一旦发生这种情况,从此 QCView 拍摄的所有快照都是空白的,直到出现 stopRendering / startRendering。即使在同一时间,另一个具有完全相同组成的 QCView 正在运行并提供良好的快照,也会发生这种情况。
快照似乎与 QCView 不同步。我尝试以更高的频率触发计时器,但它没有改变任何东西(我提到这一点是为了防止它可能与我的空白图像的主要问题有关)。
有什么想法或指示吗?
编辑:
我尝试重现:创建一个最小的项目,然后复制粘贴我的代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSRect r = NSMakeRect(0, 0, nb * 101, 101 );
feedbackwindow = [[[NSWindow alloc] initWithContentRect: r
styleMask: NSResizableWindowMask
backing: NSBackingStoreBuffered
defer: NO ] retain ];
for ( int n = 0; n < nb; n++ )
{
v[n] = [[[QCView alloc] init] autorelease];
[v[n] setFrame: NSMakeRect( 101 * n, 0, 100, 100 ) ];
[[window contentView] addSubview: v[n]];
if(![v[n] loadCompositionFromFile:[[NSBundle mainBundle] pathForResource:@"clock" ofType:@"qtz"]]) {
NSLog(@"Could not load composition");
}
[v[n] startRendering];
img[n] = [[[NSImageView alloc] init] autorelease];
[img[n] setFrame: NSMakeRect(101 * n, 0, 100, 100 ) ];
[[feedbackwindow contentView] addSubview: img[n]];
}
[feedbackwindow orderFront:nil];
[window orderFront:nil];
[self setFeedbackTimer: [NSTimer scheduledTimerWithTimeInterval: ( 0.01 )
target: self
selector: @selector(updateImage)
userInfo: nil
repeats: YES ]];
}
- (void) updateImage
{
for ( int n = 0; n < nb; n++ )
{
NSImage* snapshot = [v[n] snapshotImage];
[img[n] setImage: snapshot];
}
}
唉,我没有遇到问题...
快照在 QCViews 中已经过时,但非常好:(
看来快照检索了以前的图像而不是当前的:我制作了一个简单的 Quartz Composer 时钟,其中包含“系统时间”->“时间格式化程序(格式= ss)”->“带字符串的图像”->“精灵”晚了一秒:它们与原始时钟同时改变,但显示上一张图像...
听起来也像是一个错误,但可能与导致无效图像的错误不同...
I have a program playing quartz compositions in QCViews.
Because the QCViews are on a secondary screen, I need to display a (smaller) copy in the main screen (kind of control screen).
So I fire a timer every 0.1 seconds, take a snapshot of the QCView an set the resulting image in a NSImageView.
My problems :
The snapshot is correct about 90 % of the time but sometimes goes blank. Once this happens all snapshots taken from this QCView are blank until there is a stopRendering / startRendering. This happens even as in the same time another QCView with exactly the same composition is running and delivering good snapshots.
The snapshots seem to be out of sync with the QCView. I tried to fire the timer with a higher frequency but it did not change anything (I mention this in case it could be related to my main problem of blank images).
Any ideas or pointers ?
EDIT:
I tried to reproduce : created a minimal project then copy pasted my code :
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSRect r = NSMakeRect(0, 0, nb * 101, 101 );
feedbackwindow = [[[NSWindow alloc] initWithContentRect: r
styleMask: NSResizableWindowMask
backing: NSBackingStoreBuffered
defer: NO ] retain ];
for ( int n = 0; n < nb; n++ )
{
v[n] = [[[QCView alloc] init] autorelease];
[v[n] setFrame: NSMakeRect( 101 * n, 0, 100, 100 ) ];
[[window contentView] addSubview: v[n]];
if(![v[n] loadCompositionFromFile:[[NSBundle mainBundle] pathForResource:@"clock" ofType:@"qtz"]]) {
NSLog(@"Could not load composition");
}
[v[n] startRendering];
img[n] = [[[NSImageView alloc] init] autorelease];
[img[n] setFrame: NSMakeRect(101 * n, 0, 100, 100 ) ];
[[feedbackwindow contentView] addSubview: img[n]];
}
[feedbackwindow orderFront:nil];
[window orderFront:nil];
[self setFeedbackTimer: [NSTimer scheduledTimerWithTimeInterval: ( 0.01 )
target: self
selector: @selector(updateImage)
userInfo: nil
repeats: YES ]];
}
- (void) updateImage
{
for ( int n = 0; n < nb; n++ )
{
NSImage* snapshot = [v[n] snapshotImage];
[img[n] setImage: snapshot];
}
}
Alas I don't get the problem...
The snapshots are out of date from the QCViews but perfectly good :(
It seems that the snapshot retrieve the previous image instead of the current one : I made a simple Quartz Composer clock with "system time" -> "time formatter (format = ss)" -> "image with string" -> "sprite" and the snapshot are exactly one second late : they change at the same time as the original clock but display the previous image ...
Sounds like a bug too but probably not the same one that causes invalid images ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论