Please help me save a image taken from camera to file.
I need the filename and filepath, so I can take next action to it.
Saving to gallery will not help me, as I do not have the file name. Below is the code. and the error is
JS: TypeError: img.saveToFile is not a function
I am running tns 3.0.1
Help please.
var cameraModule = require("nativescript-camera");
var fs = require('file-system');
var imageSource = require("image-source");
var enumsModule = require('ui/enums');
var imageModule = require("ui/image");
var format = enumsModule.ImageFormat.jpeg
console.log(JSON.stringify(imageSource));
exports.takepic=function(){
console.log('take pic');
cameraModule.requestPermissions()
cameraModule.takePicture({
width: 300,
height: 300,
keepAspectRatio: true
}).then(function (imageAsset) {
console.log("Image taken!");
console.log(JSON.stringify(img));
try{
var img=imageSource.fromAsset(imageAsset);
console.log(JSON.stringify(img));
var folder = fs.knownFolders.documents().path;
console.log('folder - ', folder); // => object
var fileName = 'img_' + new Date().getTime() + '.' + format
var path = fs.path.join(folder, fileName);
console.log('path - ', path); // => correct path
img.saveToFile(path, format); // ### Execution stops here.
console.log('saved - ', saved);
console.log('saved - ');
}
catch(e){
console.log(e);
}
var imgLocal = imageSource.fromFile(path);
pageData.camera.set("cameraImage", img);
});
}
Reactions are currently unavailable
Please help me save a image taken from camera to file.
I need the filename and filepath, so I can take next action to it.
Saving to gallery will not help me, as I do not have the file name. Below is the code. and the error is
JS: TypeError: img.saveToFile is not a function
I am running tns 3.0.1
Help please.
var cameraModule = require("nativescript-camera");
var fs = require('file-system');
var imageSource = require("image-source");
var enumsModule = require('ui/enums');
var imageModule = require("ui/image");
var format = enumsModule.ImageFormat.jpeg
console.log(JSON.stringify(imageSource));
exports.takepic=function(){
console.log('take pic');
cameraModule.requestPermissions()
cameraModule.takePicture({
width: 300,
height: 300,
keepAspectRatio: true
}).then(function (imageAsset) {
console.log("Image taken!");
console.log(JSON.stringify(img));
try{ var img=imageSource.fromAsset(imageAsset); console.log(JSON.stringify(img)); var folder = fs.knownFolders.documents().path; console.log('folder - ', folder); // => object var fileName = 'img_' + new Date().getTime() + '.' + format var path = fs.path.join(folder, fileName); console.log('path - ', path); // => correct path img.saveToFile(path, format); // ### Execution stops here. console.log('saved - ', saved); console.log('saved - '); } catch(e){ console.log(e); } var imgLocal = imageSource.fromFile(path); pageData.camera.set("cameraImage", img);});
}