我正在尝试制作一个应用程序,我必须像这个应用程序一样计算相机的亮度:http: //itunes.apple.com/us/app/megaman-luxmeter/id455660266 ?mt=8
我找到了这份文件:http ://b2cloud.com.au/tutorial/obtaining-luminosity-from-an-ios-camera
但我不知道如何将它直接适应相机而不是图像。这是我的代码:
Image = [[UIImagePickerController alloc] init];
Image.delegate = self;
Image.sourceType = UIImagePickerControllerCameraCaptureModeVideo;
Image.showsCameraControls = NO;
[Image setWantsFullScreenLayout:YES];
Image.view.bounds = CGRectMake (0, 0, 320, 480);
[self.view addSubview:Image.view];
NSArray* dayArray = [NSArray arrayWithObjects:Image,nil];
for(NSString* day in dayArray)
{
for(int i=1;i<=2;i++)
{
UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png",day,i]];
unsigned char* pixels = [image rgbaPixels];
double totalLuminance = 0.0;
for(int p=0;p<image.size.width*image.size.height*4;p+=4)
{
totalLuminance += pixels[p]*0.299 + pixels[p+1]*0.587 + pixels[p+2]*0.114;
}
totalLuminance /= (image.size.width*image.size.height);
totalLuminance /= 255.0;
NSLog(@"%@ (%d) = %f",day,i,totalLuminance);
}
}
以下是问题:
“找不到实例方法'-rgbaPixels'(返回类型默认为'id')”和“使用'id'类型的表达式初始化'unsigned char *'的不兼容指针类型”
非常感谢 !=)