LynxImagePicker
Lets someone pick a photo with the phone's photo picker, or take one with its camera, and hands it back as a Blob. import { LynxImagePicker, ImagePickerError, type ImagePickerOptions, type ImagePickerSource, type ImagePickerErrorCode, type PickedImage } from '@blotch/angular-lynx';
Pick a Photo shows it in use.
Turn it on
Picking from the library needs no setting: every app ng build --platform makes has it. Only the camera needs one.
Add permissions.camera to the build target's options in angular.json, with the reason iOS shows when it asks for the camera:
What it adds:
- iOS:
NSCameraUsageDescription, the reason iOS's camera prompt shows, and the picker's camera code. - Android: the
CAMERApermission, which Android asks for before the picker opens the camera app, and the picker's camera code. The camera is declared not required, so Google Play still offers the app to devices without one.
It also turns on LynxBarcodeScanner.
Without it, the camera code is left out of both apps, and pick({ source: 'camera' }) rejects with unavailable. App Store Connect flags an app whose code uses the camera without saying why. The library picker is still there.
See Turn on device features for every setting.
Usage
API
LynxImagePicker
Only the apps --platform builds, with ng build or ng serve, have the native module behind it. The camera is only in apps whose angular.json sets permissions.camera.
Under the testing library, pick() rejects with unavailable until a spec gives it a photo.
LynxImagePicker.pick()
Opens the picker, or the camera with source: 'camera'. Resolves with the photo picked or taken, or with null when the person closes it without choosing. Rejects with an ImagePickerError, or with a RangeError for an option out of range.
One picker can be open at a time. Picking again while one is open:
- On iOS and Android, rejects with
failed. - In the web preview, resolves the open pick with
null.
LynxImagePicker.recover()
Resolves with the photo the person picked or took while Android restarted the app, which no pick() was left to resolve with, or with null when there's none. Rejects with an ImagePickerError with failed when that photo couldn't be read.
Android can end the app's screen while the picker or the camera is in front, when it needs the memory or with "Don't keep activities" on, and start it again when the person has chosen. The app starts again with it, so the pick() that opened the picker has gone. Call recover() as the app starts:
- It resolves with the photo once, prepared with the
maxDimensionandqualitythe lostpick()asked for. - It waits while Android still has to hand the restarted app the result, until the picker or the camera closes.
- It reads the photo only when it's called, so an app that never calls it doesn't read it.
- A photo nobody asks for isn't handed over after a minute, and is dropped when another picker or camera opens, even if the person cancels it, or when the person closes the app or the app ends.
ImagePickerOptions
Either option re-encodes the photo as a JPEG:
- upright, whichever way the camera stored it
- without the original's metadata
- with a white background where it was transparent
Without them, a JPEG, PNG, GIF or WebP comes back as it was picked. Any other format, such as HEIC, is re-encoded as a JPEG at full size.
A photo from the camera is always re-encoded as a JPEG.
PickedImage
- On Android,
nameis the photo's number in the library, such as1000000020.jpg: the Photo Picker doesn't share the file's own name. - A photo from the camera is named for when it was taken, such as
IMG_20261129_142305.jpg.
