Import an existing image Pixelnetica™ Document Scanning SDK for Apple iOS
Not every document comes from the live camera. You can feed an existing photo — picked from the library, received as a file, or held in memory — into the same pipeline. This is also how you exercise detection, cropping, enhancement, OCR, and export on the Simulator, which has no camera.
Create a PxPicture from your source
PxPicture initialises from whatever you have:
import DocScanningSDK
let picture = PxPicture(image) // a UIImage (e.g. from PHPicker)
// or:
let fromFile = PxPicture(fromPath: filePath) // a file-system path
let fromURL = PxPicture(fromNSURL: fileURL) // a file URL
let fromData = PxPicture(fromData: imageData) // raw image bytes
There is also an initialiser that takes a UIImage plus a metadata dictionary, when you want to carry capture metadata through.
Run the pipeline
From there it is the same flow as a camera capture. To detect and crop in one step:
let features = PxRefineFeatures()
features.rectifyAutodetectCutout() // find edges + crop + correct
picture.refine(features) // apply the processing
let corrected = picture.extractImage() // the flattened page
Then enhance (colour profiles), recognise text (OCR), and export exactly as you would for a captured page. If you want the user to confirm the detected edges, hand the picture and its cutout to the crop editor.
Tips
- This path runs on the Simulator — useful for developing and testing the non-camera stages without a device.
- Add the appropriate photo-library usage description to
Info.plistif you import from the user’s library.
See also
- Camera capture & live detection — the live path.
- Edge detection & cropping · The processing pipeline