gpt4 book ai didi

ios - 错误的接收器类型 'CGImageRef'(又名 'CGImage *')

转载 作者:行者123 更新时间:2023-11-29 01:00:37 25 4
gpt4 key购买 nike

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

但现在我在发送消息时收到“Bad receiver type 'CGImageRef' (aka '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 的其他一切都工作得很好,据我所知这应该是正确的方法。

请看一下这个问题的糟糕表现,因为我仍然需要学习如何正确格式化所有内容。

提前致谢!

最佳答案

您的线路:

manipulated = [imageRef colorMiddle];

需要:

manipulated = [self colorMiddle:imageRef];

colorMiddle: 是您的 ViewController 类中的一个方法。

关于ios - 错误的接收器类型 'CGImageRef'(又名 'CGImage *'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37033988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com