2016-04-22 4 views
0

私はリアルタイムのビデオアプリケーションをやっています。今まで私は画像(フレーム)を連続的に送信するという点を解決し、別のラップトップでもこの画像を受信できます。ポイントはどのようにカスタムビューコントロールで画像を表示し、それはビデオのように見えるか? つまり、私は多くのNSImageオブジェクトを持っており、それらをビデオのように見たいと思います。 CGColorSpaceRefを使用していますか?Mac OS X用の新しいプログラミングです。 誰かに何かコードを教えてもらえますか?カスタムビューコントロールで連続した画像を表示する方法

答えて

0
#import "ViewController.h" 
#import <Quartz/Quartz.h> 

@interface ViewController() 
{ 
    NSArray *activityAnimationImages; 
    IBOutlet NSImageView *activityImageView; 
} 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
[super viewDidLoad]; 

// Do any additional setup after loading the view. 

NSMutableArray *array = [NSMutableArray array]; 

for (NSUInteger i = 0; i<=29; i++) 
{ 
    //Preloader is a set of images 
    NSImage *image = [NSImage imageNamed:[NSString stringWithFormat:@"Preloader_10_000%02lu",(unsigned long)i]]; 
    [array addObject:image]; 
} 

activityAnimationImages = [NSArray arrayWithArray:array]; 

//Create layer 
CALayer *layer = [CALayer layer]; 
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"]; 
[animation setCalculationMode:kCAAnimationDiscrete]; 
[animation setDuration:1.0f]; 
[animation setRepeatCount:HUGE_VALF]; 
[animation setValues:activityAnimationImages]; 

[layer setFrame:NSMakeRect(0, 0, 100, 100)]; 
layer.bounds = NSMakeRect(0, 0, 100, 100); 
[layer addAnimation:animation forKey:@"contents"]; 

[activityImageView setLayer:[CALayer layer]]; 
[activityImageView setWantsLayer:YES]; 
[activityImageView.layer addSublayer:layer]; 
} 
+0

ありがとうございます。これを試してみましょう。 –

+0

@ X.Rodiそれがうまくいけば、答えを受け入れてください:) – Jeyamahesan

関連する問題