From 36844c63f29ad50d4b6f309fb0193fa089e70923 Mon Sep 17 00:00:00 2001 From: Michael Pope Date: Mon, 5 Aug 2019 14:49:20 +1000 Subject: [PATCH] Add how to save the imageAsset I've spent a lot of time trying to find this information as I wanted to save a thumbnail and thought the best place for it would be in the nativescript-camera documentation. --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 3429308..ec111bf 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,28 @@ camera.takePicture(options). }); ``` +### Save a picture + +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; + +``` TypeScript + const source = new ImageSource(); + source.fromAsset(imageAsset) + .then((imageSource: ImageSource) => { + const folderPath = knownFolders.documents().path; + const fileName = "test.jpg"; + const filePath = path.join(folderPath, fileName); + const saved: boolean = imageSource.saveToFile(filePath, "jpg"); + if (saved) { + console.log("Gallery: " + this._dataItem.picture_url); + console.log("Saved: " + filePath); + console.log("Image saved successfully!"); + } + }); +``` + +This could be used to create thumbnails for quick display within your application. + ### Check if the device has available camera The first thing that the developers should check if the device has an available camera.