Skip to content

Commit 9e9ad65

Browse files
author
Zdravko
authored
Merge pull request #216 from NativeScript/zbranzov/save
chore: Add how to save the imageAsset #215
2 parents a35e28a + e722119 commit 9e9ad65

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ camera.takePicture(options).
168168
});
169169
```
170170

171+
### Save a picture
172+
173+
To save a picture with the width & height that you have defined you must use the imageAsset and save it to the file system like so:
174+
175+
``` TypeScript
176+
const source = new ImageSource();
177+
source.fromAsset(imageAsset)
178+
.then((imageSource: ImageSource) => {
179+
const folderPath = knownFolders.documents().path;
180+
const fileName = "test.jpg";
181+
const filePath = path.join(folderPath, fileName);
182+
const saved: boolean = imageSource.saveToFile(filePath, "jpg");
183+
if (saved) {
184+
console.log("Gallery: " + this._dataItem.picture_url);
185+
console.log("Saved: " + filePath);
186+
console.log("Image saved successfully!");
187+
}
188+
});
189+
```
190+
191+
This could be used to create thumbnails for quick display within your application.
192+
171193
### Check if the device has available camera
172194

173195
The first thing that the developers should check if the device has an available camera.

0 commit comments

Comments
 (0)