接收器类型错误 'CGImageRef'(又名 'CGImage *')
Bad receiver type 'CGImageRef' (aka 'CGImage *')
我是一名 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
class.
上的一种方法
我是一名 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
class.