错误的接收器类型“CGImageRef”(又名“CGImage *”)
Posted
技术标签:
【中文标题】错误的接收器类型“CGImageRef”(又名“CGImage *”)【英文标题】:Bad receiver type 'CGImageRef' (aka 'CGImage *') 【发布时间】:2016-05-04 17:07:52 【问题描述】:我是一名 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】:您的线路:
manipulated = [imageRef colorMiddle];
需要:
manipulated = [self colorMiddle:imageRef];
colorMiddle:
是 ViewController
类的一个方法。
【讨论】:
以上是关于错误的接收器类型“CGImageRef”(又名“CGImage *”)的主要内容,如果未能解决你的问题,请参考以下文章
类型“NSFastEnumerationIterator.Element”(又名“Any”)不符合协议“AnyObject”
react-native 无法构建 ios:(错误 xcode Flipper)Typedef 重新定义不同类型('uint8_t'(又名'unsigned char')与'enum clockid_
上下文类型“Void”(又名“()”)不能与数组字面量一起使用