0

我试图从一些奇怪的字节构建一个 NSImage 。我使用 BlackMagic SDK 来获取接收帧的字节数:

unsigned char* frame3 = NULL;
unsigned char* frame2 = (Byte*)malloc(699840);

videoFrame->GetBytes ( (void**)&frame3);
memcpy(frame2, frame3, 699840);

NSData* data = [NSData dataWithBytes:frame2 length:sizeof(frame2) ];
NSImage *image = [[NSImage alloc] initWithData:data];

//(till now i use statically 699840, because i know its size)

为什么我说字节很奇怪是“frame2”的内容看起来像这样:

printf("content: %s",frame2);

\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200 \200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200 \200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200 \200\200.........\200(到最后)

它应该是空白的黑框。

有人知道我怎么能弄清楚这个吗?

4

1 回答 1

0

您应该使用这些 api 从数据字节中获取图像。

NSString *filePath = [yourDirectory stringByAppendingPathComponent:@"imageName.jpg"];

[数据 writeToFile:filePath atomically:YES];

于 2012-10-19T10:56:52.513 回答