Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 能否使NSView对CIImages使用软件渲染?_Cocoa_Nsimageview_Ciimage - Fatal编程技术网

Cocoa 能否使NSView对CIImages使用软件渲染?

Cocoa 能否使NSView对CIImages使用软件渲染?,cocoa,nsimageview,ciimage,Cocoa,Nsimageview,Ciimage,从前面的一个问题来看, , 通过告诉CIContext进行软件渲染,我学会了解决CoreImage问题。我现在正试图找出当AppKit尝试绘制我已设置为使用以下代码显示CIImage的NSImageView时发生的崩溃: - (void)setCIImage:(CIImage *)processedImage; { NSSize size = [processedImage extent].size; if (size.width == 0) { [self se

从前面的一个问题来看, , 通过告诉
CIContext
进行软件渲染,我学会了解决CoreImage问题。我现在正试图找出当AppKit尝试绘制我已设置为使用以下代码显示
CIImage
NSImageView
时发生的崩溃:

- (void)setCIImage:(CIImage *)processedImage;
{
    NSSize size = [processedImage extent].size;
    if (size.width == 0) {
        [self setImage:nil];
        return;
    }
    NSData * pixelData = [[OMFaceRecognizer defaultRecognizer] imagePlanarFData:processedImage];
    LCDocument * document = [[[self window] windowController] document];
    [[NSNotificationCenter defaultCenter] postNotificationName:LCCapturedImageNotification
                                                        object:document
                                                      userInfo:@{ @"data": pixelData, @"size": [NSValue valueWithSize:size] }];
#if 1
    static dispatch_once_t onceToken;
    static CGColorSpaceRef colorSpace;
    static size_t bytesPerRow;
    dispatch_once(&onceToken, ^ {
        colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray);
        bytesPerRow = size.width * sizeof(float);
    });
    // For whatever bizarre reason, CoreGraphics uses big-endian floats (!)
    const float * data = [[[OMFaceRecognizer defaultRecognizer] byteswapPlanarFData:pixelData
                                                                        swapInPlace:NO] bytes];
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, bytesPerRow * size.height, NULL);
    CGImageRef renderedImage = CGImageCreate(size.width, size.height, 32, 32, bytesPerRow, colorSpace, kCGImageAlphaNone | kCGBitmapFloatComponents, provider, NULL, false, kCGRenderingIntentDefault);
    CGDataProviderRelease(provider);
    NSImage * image = [[NSImage alloc] initWithCGImage:renderedImage
                                                  size:size];
    CGImageRelease(renderedImage);
#else
    NSCIImageRep * rep = [NSCIImageRep imageRepWithCIImage:processedImage];
    NSImage * image = [[NSImage alloc] initWithSize:size];
    [image addRepresentation:rep];
#endif
    [self setImage:image];
}

是否有某种方法可以让
NSImageView
使用软件渲染?我在IB中环顾四周,但我没有看到任何看起来很有希望的东西…

我不确定,但当我得知CG并没有很好地处理灰度浮动图像时,我并不感到惊讶。这可能很好,但我遇到了一些问题,比如它不能处理浮点RGBA数据,它必须是ARGB(或者可能是相反的?)。支持的格式没有很好的文档记录,但我看到当您使用不支持的格式时,它会导致一些奇怪的问题。我相信,它确实支持这一点。将
kCGBitmapByteOrder32Big
(或
Little
)常量添加到
CGImageCreate()
中的位图信息参数中是否有任何效果?@user1118321:啊,是的,添加
kCGBitmapByteOrder32Little
确实允许跳过免费的字节交换……谢谢。