【发布时间】:2015-11-11 11:36:44
【问题描述】:
我正在制作一个也支持视频的 voip 应用程序,
对于视频,我以 YUV 格式获取数据并使用 libvpx 进行解码,
然后我将RGB数据,
现在显示我正在使用 NSImageView 我将更改 NSImage,请参考下面的代码
-(void)gotNewRGBBuffer:(void *)imageData Height:(int)height Width:(int)width Scan:(int)scan VideoId:(const char *)pId{
@autoreleasepool {
// display the image (on the UI thread)
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(unsigned char **)&imageData
pixelsWide:width pixelsHigh:height
bitsPerSample:8
samplesPerPixel:3 // or 4 with alpha
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0
bytesPerRow:scan // 0 == determine automatically
bitsPerPixel:24]; // 0 == determine automatically
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
[image addRepresentation:bitmap];
if ( ![NSThread isMainThread]){
[self performSelectorOnMainThread:@selector(updateImage:) withObject:image waitUntilDone:NO];
}else{
[self updateImage:image];
}
}
}
还有更新图片的功能,
-(void)updateImage:(NSImage *)pNewLocalImage{
[self pImageView].image = pNewLocalImage;
[[self pImageView] setNeedsDisplay:YES];
NSLog(@" Updating the image ");
}
这是有效的,但占用了相当多的内存,所以我的问题是,有没有其他方法可以优化它!
【问题讨论】:
标签: objective-c macos video-streaming nsimage nsimageview