接收器类型'CGImageRef'(又名'CGImage *')

时间:2016-05-04 17:07:53

标签: ios objective-c cgimageref

我是iOS初学者,正在关注How can I manipulate the pixel values in a CGImageRef in Xcode学习改变CGImages。我稍微更改了代码,以便图像中的中间像素应该涂成红色,而不是为每个像素交换蓝色和红色缓冲区。

但是现在我收到了“错误的接收器类型'CGImageRef'(又名'CGImage *')”错误发送消息

    manipulated = [imageRef colorMiddle];

在这个函数中:

    - (void)renderColorFrame:(CMSampleBufferRef)sampleBuffer
     {

 CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);

size_t cols = CVPixelBufferGetWidth(pixelBuffer);
size_t rows = CVPixelBufferGetHeight(pixelBuffer);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

unsigned char *ptr = (unsigned char *) CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);

NSData *data = [[NSData alloc] initWithBytes:ptr length:rows*cols*4];
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

CGBitmapInfo bitmapInfo;
bitmapInfo = (CGBitmapInfo)kCGImageAlphaNoneSkipFirst;
bitmapInfo |= kCGBitmapByteOrder32Little;

CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);

CGImageRef imageRef = CGImageCreate(cols,
                                    rows,
                                    8,
                                    8 * 4,
                                    cols*4,
                                    colorSpace,
                                    bitmapInfo,
                                    provider,
                                    NULL,
                                    false,
                                    kCGRenderingIntentDefault);



//hier image ref verarbeiten!!
manipulated = [imageRef colorMiddle]; //here

leftImage = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, self.view.frame.size.width * 6/7, self.view.frame.size.height));

rightImage = CGImageCreateWithImageInRect(imageRef, CGRectMake(self.view.frame.size.width / 7, 0, self.view.frame.size.width * 6/7, self.view.frame.size.height));

    //left image
_colorImageViewL.image = [[UIImage alloc] initWithCGImage:leftImage/*imageRef*/];

    //right image
_colorImageViewR.image = [[UIImage alloc]initWithCGImage:rightImage/*imageRef*/];

//Full
 //  _colorImageViewFull.image = [[UIImage alloc]initWithCGImage:imageRef];


CGImageRelease(imageRef);
CGImageRelease(leftImage);
CGImageRelease(rightImage);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);

}

我不明白为什么我在这里得到这个错误,因为消息应该使用匹配的参数发送:

        @interface ViewController () <AVCaptureVideoDataOutputSampleBufferDelegate> {

        STSensorController *_sensorController;

        AVCaptureSession *_avCaptureSession;
        AVCaptureDevice *_videoDevice;

        UIImageView *_depthImageView;
        //UIImageView *_depthImageView2;
        //UIImageView *_normalsImageView;

        //Left
        UIImageView *_colorImageViewL;

        //right
        UIImageView *_colorImageViewR;

        //Full
        //UIImageView *_colorImageViewFull;

        uint16_t *_linearizeBuffer;
        uint8_t *_coloredDepthBuffer;
        uint8_t *_normalsBuffer;

        STNormalEstimator *_normalsEstimator;

        UILabel* _statusLabel;

        GLKMatrix4 _projection;

        CGImageRef leftImage;
        CGImageRef rightImage;
        CGImageRef manipulated;




        AppStatus _appStatus;

    }

    - (BOOL)connectAndStartStreaming;
    - (void)renderDepthFrame:(STDepthFrame*)depthFrame;
    - (void)renderNormalsFrame:(STDepthFrame*)normalsFrame;
    - (void)renderColorFrame:(CMSampleBufferRef)sampleBuffer;
    - (void)setupColorCamera;
    - (void)startColorCamera;
    - (void)stopColorCamera;
    - (CGImageRef)colorMiddle:(CGImageRef)image; //here

@end 

有谁知道导致错误的原因以及如何解决此问题? 我只是想不出任何东西,因为使用CGImageRefs的其他所有工作都很好,据我所知,这应该是正确的方法。

请查看这个问题的不良外观,因为我仍然需要学习如何正确地格式化所有内容。

提前致谢!

1 个答案:

答案 0 :(得分:1)

你的专栏:

manipulated = [imageRef colorMiddle];

需要:

manipulated = [self colorMiddle:imageRef];

colorMiddle:ViewController课程的一种方法。