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."
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.