当ICScannerFunctionalUnit设置为以黑白扫描时,ImageCaptureCore错误-9933(ImageCaptureCore error -9933 when ICScannerFunctionalUnit set to scan in black & white)

我正在制作一个应用程序,可以轻松扫描到多页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的扫描部分提供的文档非常少,但我发现这些属性描述了本网站上黑白扫描的阈值,但它们都不适用于我。

我知道这是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."

I'm making an application to easily scan to multiple page pdf files. The project is on GitHub, just in case you want to have a look at all of the project code.

I'm having an issue with scanning in black & white.

This is the method that gets called when I press the button to start scanning.

- (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]; } }

I'm setting the pixelDataType to an integer that I get from an NSSegmentedControl. When the first segment is selected this will return 0, which is the same as ICScannerPixelDataTypeBW.

However, despite everything working fine when the second and the third segment are selected (which are ICScannerPixelDataTypeGray and ICScannerPixelDataTypeRGB), the scanner does nothing when set to scan black & white.

There is very little documentation available on the scanning part of ImageCaptureCore, but I found those properties describing a threshold for black & white scanning on this website, but none of them worked for me.

I know this is a part of the ImageCaptureCore API that doesn't get used by many people very often, but I really hope someone knows, or at least can find out, a solution to my problem.

Edit:

I added - (void)device:(ICDevice *)device didEncounterError:(NSError *)error to my implementation and logged the error, which is:

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扫描。

由于我不能将赏金奖励给我自己的问题,我将奖励我得到提示的问题。

With a little hint (intentional or not) from the other answer, I figured things out by myself.

What you have to do is to set bitDepth to ICScannerBitDepth1Bit, as what you're trying to scan is a 1 bit per pixel image.

This in turn disables scanning in grayscale or rgb.

Since I can't award bounties to my own questions, I will award the bounty to the question I got the hint from.

更多推荐