Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

cordova-camera-preview / Ionic? #39

Open
RZR666 opened this issue Jul 18, 2019 · 0 comments
Open

cordova-camera-preview / Ionic? #39

RZR666 opened this issue Jul 18, 2019 · 0 comments

Comments

@RZR666
Copy link

RZR666 commented Jul 18, 2019

Hi,

Has anyone got this working in Ionic?

I pass in a file location and it keeps telling me this is not a JPG or PNG?

When it is.

``import { File } from '@ionic-native/file/ngx';
import { Ng2ImgToolsService } from 'ng2-img-tools';
import { CameraPreview, CameraPreviewPictureOptions } from '@ionic-native/camera-preview/ngx';

constructor(private file: File, public cameraPreview: CameraPreview, private ng2ImgToolsService: Ng2ImgToolsService) { }

    takePhoto()
      {
        this.cameraPreview.takePicture({quality: .7}).then((path) => {

          let tempPath = path[0].substr(0, path[0].lastIndexOf('/') + 1);
          let tempFileName = path[0].replace(tempPath, ""); 
          let fullTempPath = 'file://' + tempPath;

          var newFilename = this.createFileName();
          var permLocation = this.file.dataDirectory + newFilename;

          // Copy Image to Perm Directory....
          this.file.copyFile(fullTempPath, tempFileName, this.file.dataDirectory, newFilename).then(success => {

            var localLocation = window.Ionic.WebView.convertFileSrc(permLocation);

            this.ng2ImgToolsService.resize([localLocation], 640, 640).subscribe(result => {
                //all good, result is a file
                console.info(result);

            }, error => { });

          }, error => { });

        }, error => { });
      }``
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant