首页 文章

如何访问图像src nativescript

提问于
浏览
1

如何从nativescript相机模块获取照片src?

public takePicture() {
  cameraModule.takePicture().then(function(picture) {
      console.log("Result is an image source instance");
      var image = new imageModule.Image();
      image.imageSource = picture;
      console.dir(picture);
  });
}

console.dir输出:

=== dump(): dumping members ===
{
    "android": {
        "constructor": "constructor()function () { [native code] }"
    }
}
=== dump(): dumping function and properties names ===
loadFromResource()
fromResource()
loadFromFile()
fromFile()
loadFromData()
fromData()
loadFromBase64()
fromBase64()
setNativeSource()
saveToFile()
height: 480
width: 640
=== dump(): finished ===

我如何获得图像src?

我想将它上传到firebase,所以我需要src .

2 回答

  • 4

    弄清楚,这有效:

    public takePicture() {
        cameraModule.takePicture().then((picture) => {
            var image = new imageModule.Image();
            image.imageSource = picture;
    
    
            let savePath = fs.knownFolders.documents().path;
            let fileName = 'img_' + new Date().getTime() + '_' + this.currentUserId.getValue() + '.' + enumsModule.ImageFormat.jpeg;
            let filePath = fs.path.join( savePath, fileName );
            picture.saveToFile(filePath, enumsModule.ImageFormat.jpeg);
    
            this.photoService.uploadImage(filePath, fileName).then((data) => {
              this._router.navigate(["/upload", fileName, this.currentUserId.getValue()]);
            }); 
        }); 
      }
    
  • 2

    要上传到firebase,您需要通过其路径上传图片:

    let imgsrc = this.imageSource.fromNativeSource(data);
    let path = this.utils.documentsPath(randomName);
    imgsrc.saveToFile(path, this.enums.ImageFormat.png);
    
    this.firebase.uploadFile(path).then((uploadedFile: any) => {
       this.appSettings.setString("fileName", uploadedFile.name);         
          this.router.navigate(['/soundcloud']);
          this.LoadingIndicator.hide();          
    }, (error: any) => {
       alert("File upload error: " + error);
     });
    }, (err: any) => {
       alert(err);
    

    });

相关问题