0
你好,这里是我试图做的事:多的操作队列不同的优先级
- 我有一个照片处理应用程序,需要使用AVFoundation
- 我有一个处理设备位置的DeviceMotion队列图片在60Hz时
- 拍摄图像时,需要剪切并保存。 DeviceMotion需要保持运行和接口更新没有延迟
我所看到的是:从图像作物的持续时间冻结DeviceMotion队列的接口更新。
这是我的开始更新为DeviceMotion:
self.motionManager.deviceMotionUpdateInterval = 1.0f/60.0f;
gyroQueue = [[NSOperationQueue alloc] init];
[self.motionManager startDeviceMotionUpdatesToQueue:gyroQueue withHandler:^(CMDeviceMotion *motion, NSError *error){
[NSThread setThreadPriority:1.0];
[self processMotion:motion withError:error];
}];
当图像从AVFoundation返回它被添加到队列进行处理:
imageProcessingQueue = [[NSOperationQueue alloc] init];
[imageProcessingQueue setName:@"ImageProcessingQueue"];
[imageProcessingQueue setMaxConcurrentOperationCount:1];
//[imageProcessingQueue addOperationWithBlock:^{
//[self processImage:[UIImage imageWithData:imageData]];
//}];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(processImage:) object:[UIImage imageWithData:imageData]];
[operation setThreadPriority:0.0];
[operation setQueuePriority:NSOperationQueuePriorityVeryLow];
[imageProcessingQueue addOperation:operation];
和用于处理图像的方法:
- (void)processImage:(UIImage*)image {
CGSize cropImageSize = CGSizeMake(640,960);
UIImage *croppedImage = [image resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:cropImageSize interpolationQuality:kImageCropInterpolationQuality];
NSData *compressedImageData = UIImageJPEGRepresentation(croppedImage, kJpegCompression);
[self.doc addPhoto:compressedImageData];
}
的问题是:
次- devicemotion更新阻塞图像作物的持续时间时,使用NSOperationQueue
如果我处理使用performSelectorInBackground图像被处理的图像 - 它可以作为所希望的(无延迟DeviceMotion队列)
[self performSelectorInBackground:@selector(processImage:) withObject:[UIImage imageWithData:imageData]];
想知道我对后台线程的理解需要更新吗? :)
PS。我问这个问题早,但毫无进展,所以这是一个重职
你在哪里设置'你的操作队列queuePriority'? – nielsbot 2013-03-08 19:06:00
我正在NSInvocationOperation上设置queuePriority,请参阅上面的更新代码... – 2013-03-08 19:23:50
为什么您将优先级设置为'0.0'而不是'NSOperationQueuePriorityVeryHigh'或'NSOperationQueuePriorityVeryHigh'之一? “0”(不是浮点数)是标准优先级。 – nielsbot 2013-03-08 23:44:56