我正在制作一个应用程序来轻松扫描到多页 pdf 文件。该项目位于GitHub ,以防万一您想查看所有项目代码。
我在黑白扫描时遇到问题。
这是当我按下按钮开始扫描时调用的方法。
- (IBAction)scan:(id)sender {
//Get the selected scanner and it's functional unit
ICScannerDevice *scanner = [self selectedScanner];
ICScannerFunctionalUnit *unit = [scanner selectedFunctionalUnit];
//If there is no scan or overviewscan in progress
if (![unit overviewScanInProgress] && ![unit scanInProgress]) {
//Setup the functional unit and start the scan
[unit setScanArea:[self scanArea]];
[unit setResolution:[[unit supportedResolutions] indexGreaterThanOrEqualToIndex:[[resolutionPopUpButton selectedItem] tag]]];
[unit setBitDepth:ICScannerBitDepth8Bits];
[unit setMeasurementUnit:ICScannerMeasurementUnitCentimeters];
[unit setThresholdForBlackAndWhiteScanning:0];
[unit setUsesThresholdForBlackAndWhiteScanning:YES];
[unit setPixelDataType:[kindSegmentedControl selectedSegment]];
[scanner requestScan];
} else {
//Cancel the ongoing scan
[scanner cancelScan];
}
}
我将 pixelDataType
设置为从 NSSegmentedControl
获取的整数。选择第一个段时,将返回 0,与 ICScannerPixelDataTypeBW
相同。
但是,尽管选择第二个和第三个段(即 ICScannerPixelDataTypeGray
和 ICScannerPixelDataTypeRGB
)时一切正常,但扫描仪在设置为扫描黑白时不执行任何操作白色。
关于ImageCaptureCore
的扫描部分的可用文档非常少,但我发现这些属性描述了this website上的黑白扫描阈值。 ,但它们都不适合我。
我知道这是 ImageCaptureCore API 的一部分,很多人并不经常使用它,但我真的希望有人知道,或者至少能够找到解决我的问题的方法。
编辑:
我在我的实现中添加了 - (void)device:(ICDevice *)device didEncounterError:(NSError *)error
并记录了错误,即:
2014-02-01 21:55:16.260 Scanner[4131:903] Error Domain=com.apple.ImageCaptureCore Code=-9933 UserInfo=0x1005763f0 "An error occurred during scanning."
最佳答案
通过其他答案的一点提示(有意或无意),我自己解决了问题。
您要做的就是将 bitDepth
设置为 ICScannerBitDepth1Bit
,因为您要扫描的是每像素 1 位的图像。
这又会禁用灰度或 RGB 扫描。
由于我无法向我自己的问题授予赏金,因此我会将赏金授予我从中得到提示的问题。
关于objective-c - 当 ICScannerFunctionalUnit 设置为黑白扫描时,ImageCaptureCore 错误 -9933,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21502161/