Skip to content

Commit

Permalink
feat(android): Accept path while taking picture in android (react-nat…
Browse files Browse the repository at this point in the history
…ive-camera#2769)

* Accept path while taking picture in android

* docs(context): change readme to add path option while taking picture
  • Loading branch information
AsminBudha committed Apr 5, 2020
1 parent e7ed948 commit 3ee43d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ public void takePicture(final ReadableMap options, final Promise promise, final
mBgHandler.post(new Runnable() {
@Override
public void run() {
final File path = options.hasKey("path") ? new File(options.getString("path")) : cacheDirectory;

mPictureTakenPromises.add(promise);
mPictureTakenOptions.put(promise, options);
mPictureTakenDirectories.put(promise, cacheDirectory);
mPictureTakenDirectories.put(promise, path);

try {
RNCameraView.super.takePicture(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ protected WritableMap doInBackground(Void... voids) {
if (!mOptions.hasKey("doNotSave") || !mOptions.getBoolean("doNotSave")) {

// Prepare file output
File imageFile = new File(RNFileUtils.getOutputFilePath(mCacheDirectory, ".jpg"));
File imageFile;
if(mCacheDirectory.isDirectory()){

imageFile = new File(RNFileUtils.getOutputFilePath(mCacheDirectory, ".jpg"));
}
else{
imageFile=mCacheDirectory;
}
imageFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(imageFile);

Expand Down
22 changes: 13 additions & 9 deletions docs/RNCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ExampleApp extends PureComponent {
);
}

takePicture = async() => {
takePicture = async () => {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
Expand Down Expand Up @@ -217,8 +217,8 @@ On iOS, focusing will not change the exposure automatically unless autoExposure
Hint:
for portrait orientation, apply 90° clockwise rotation + translation: [Example](https://gist.github.com/Craigtut/6632a9ac7cfff55e74fb561862bc4edb)


### iOS `onSubjectAreaChanged`

iOS only.

if autoFocusPointOfInterest is set, this event will be fired when a substancial change is detected with the following object: `{ nativeEvent: { prevPoint: { x: number; y: number; } } }`
Expand Down Expand Up @@ -287,6 +287,7 @@ The idea is that you select the appropriate white balance setting for the type o
Use the `whiteBalance` property to specify which white balance setting the camera should use.

### `exposure`

Value: float from `0` to `1.0`, or `-1` (default) for auto.

Sets the camera's exposure value.
Expand Down Expand Up @@ -340,8 +341,8 @@ Note: Must also provide cameraViewDimensions prop for Android device
An `{width:, height: }` object which defines the width and height of the cameraView. This prop is used to adjust the effect of Aspect Raio for rectOfInterest area on Android

### `Android` `playSoundOnCapture`
Boolean to turn on or off the camera's shutter sound (default false). Note that in some countries, the shutter sound cannot be turned off.

Boolean to turn on or off the camera's shutter sound (default false). Note that in some countries, the shutter sound cannot be turned off.

### `iOS` `videoStabilizationMode`

Expand Down Expand Up @@ -407,7 +408,6 @@ iOS only. Function to be called when the camera audio session is interrupted or

iOS only. Function to be called when the camera audio session is connected. This will be fired the first time the camera is mounted with `captureAudio={true}`, and any time the audio device connection is established. Note that this event might not always fire after an interruption due to iOS' behavior. For example, if the audio was already interrupted before the camera was mounted, this event will only fire once a recording is attempted.


### `onPictureTaken`

Function to be called when native code emit onPictureTaken event, when camera has taken a picture, but before all extra processing happens. This can be useful to allow the UI to take other pictures while the processing of the current picture is still taking place.
Expand All @@ -425,7 +425,6 @@ Event will contain the following fields:

Function to be called when native code stops recording video, but before all video processing takes place. This event will only fire after a successful video recording, and it will not fire if video recording fails (use the error returned from `recordAsync` instead).


### Bar Code Related props

### `onBarCodeRead`
Expand Down Expand Up @@ -501,6 +500,7 @@ Like `onBarCodeRead`, but using Firebase MLKit to scan barcodes. More info can b
Like `barCodeTypes`, but applies to the Firebase MLKit barcode detector.
Example: `<RNCamera googleVisionBarcodeType={RNCamera.Constants.GoogleVisionBarcodeDetection.BarcodeType.DATA_MATRIX} />`
Available settings:

- CODE_128
- CODE_39
- CODE_93
Expand Down Expand Up @@ -578,12 +578,13 @@ Supported options:
- `mirrorImage` (boolean true or false). Use this with `true` if you want the resulting rendered picture to be mirrored (inverted in the vertical axis). If no value is specified `mirrorImage:false` is used.

- `writeExif`: (boolean or object, defaults to true). Setting this to a boolean indicates if the image exif should be preserved after capture, or removed. Setting it to an object, merges any data with the final exif output. This is useful, for example, to add GPS metadata (note that GPS info is correctly transalted from double values to the EXIF format, so there's no need to read the EXIF protocol).

```js
writeExif = {
"GPSLatitude": latitude,
"GPSLongitude": longitude,
"GPSAltitude": altitude
}
GPSLatitude: latitude,
GPSLongitude: longitude,
GPSAltitude: altitude,
};
```

- `exif` (boolean true or false) Use this with `true` if you want a exif data map of the picture taken on the return data of your promise. If no value is specified `exif:false` is used.
Expand All @@ -598,6 +599,8 @@ writeExif = {

- `orientation` (string or number). Specifies the orientation that us used for taking the picture. Possible values: `"portrait"`, `"portraitUpsideDown"`, `"landscapeLeft"` or `"landscapeRight"`.

- `path` (file path on disk). Specifies the path on disk to save picture to.

The promise will be fulfilled with an object with some of the following properties:

- `width`: returns the image's width (taking image orientation into account)
Expand Down Expand Up @@ -730,6 +733,7 @@ Read more about [react-native-barcode-mask](https://github.com/shahnawaz/react-n
### @nartc/react-native-barcode-mask

A rewritten version of `react-native-barcode-mask` using `Hooks` and `Reanimated`. If you're already using `react-native-reanimated` (`react-navigation` dependency) then you might benefit from this rewritten component.

- Customizable
- Provide custom hook to "scan barcode within finder area"

Expand Down

0 comments on commit 3ee43d4

Please sign in to comment.