How to view continuous images in the Custom View Control

75 views Asked by At

I am doing a real-time video application.Until now I solve the point that continuously sending the images(frames),and also I can receive this images in another laptop.But the point that how to view the images in the Custom View Control,and make it looks like a video? In other words,I have many NSImage objects,and I want to view them like a video. UsingCGColorSpaceRef?I am new to cocoa programming for Mac OS X. Can anybody give me some code?

1

There are 1 answers

2
Jeyamahesan On
#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];
}