正确加载到NSBitmapImageRep中

时间:2016-05-13 06:07:22

标签: c++ cocoa opencv

我正在尝试在窗口(大小为200X200)中显示图像(带有alpha值)。图像被加载到OpenCV Mat数据结构中。 我正在加载的图片如下所示:

enter image description here

显示时看到的图像如下所示:

enter image description here

我用来加载Bitmap的代码如下:

        NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:200
    pixelsHigh:200
    bitsPerSample:8
    samplesPerPixel:4
    hasAlpha:YES
    isPlanar:NO
    colorSpaceName:NSDeviceRGBColorSpace
    bytesPerRow:(200*4)
    bitsPerPixel:32] autorelease];
    memcpy(imageRep.bitmapData,paintBuffer.data,160000);
    NSSize imageSize = NSMakeSize(200,200);
    NSImage* myImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];

[myImage addRepresentation:imageRep];
    g_imageView setImage:myImage];

更新

我最初读的是BGRA而不是预期的RGBA。在改变这一点时,我只是在上面得到一个红色版本的图像,如下所示:

enter image description here

0 个答案:

没有答案