nstudio / nativescript-camera-plus

MIT License
79 stars 50 forks source link

Input SIZE not working correctly #154

Closed calleja23 closed 3 years ago

calleja23 commented 3 years ago
Android 10 problems. From one day to the next the size of the camera has changed.
Before I took the size of the entire screen and respected it.
Right now it occupies half in some devices. In others it does not load correctly the camera remains black and the errors that I attach below.

Samsung Galaxy A40 (ANDROID 10) IMG_20210222_113036

Nokia 3.1 (ANDROID 10) IMG_20210222_113123 Honor play (ANDROID 9) 20210222_113208

My dependencies:

tns-android-version:6.5.3 "dependencies":{ "@angular/animations": "~8.2.0", "@angular/common": "~8.2.0", "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", "@nativescript/theme": "~2.2.1", "@nstudio/nativescript-camera-plus": "^3.3.0", "log4js": "^6.3.0", "nativescript-angular": "~8.20.3", "nativescript-aws-sdk": "0.0.4", "nativescript-background-http": "^4.2.1", "nativescript-barcodescanner": "^3.4.2", "nativescript-downloader": "^2.1.5", "nativescript-geolocation": "^5.1.0", "nativescript-handle-file": "^4.0.0", "nativescript-mediafilepicker": "^3.0.2", "nativescript-orientation": "^2.2.5", "nativescript-plugin-firebase": "^10.5.2", "nativescript-webview-interface": "^1.4.3", "nativescript-wifi-info": "0.0.5", "nativescript-zip": "^4.0.2", "reflect-metadata": "~0.1.12", "rxjs": "^6.6.3", "tns-core-modules": "^6.5.25", "zone.js": "~0.9.1" }, "devDependencies":{ "@angular/compiler-cli": "~8.2.0", "@ngtools/webpack": "~8.2.0", "@types/node": "^14.14.7", "nativescript-dev-webpack": "~1.5.1", "tns-android": "6.5.3", "tns-ios": "6.5.4", "typescript": "~3.5.3" }

import { ImageAsset } from '@nativescript/core/image-asset';
import { ImageSource } from '@nativescript/core/image-source';
import { CameraPlus } from '@nstudio/nativescript-camera-plus';
import {screen} from "tns-core-modules/platform/platform"
import { Location } from "@angular/common";
import * as orientations from "nativescript-orientation";
import {getString,setString,remove,clear} from "tns-core-modules/application-settings";
import * as bgHttp from "nativescript-background-http";
var bindingDist;

@Component({
  selector: 'ns-capture',
  moduleId: module.id,
  templateUrl: './camera.component.html',
  styleUrls:['./camera.component.css'],
  changeDetection:ChangeDetectionStrategy.OnPush
})
export class CameraComponent implements OnInit, OnDestroy {
  private cam: CameraPlus;
  public imageSource: ImageSource;
  public size= screen.mainScreen.heightDIPs-177;
  public events: { eventTitle: string, eventData: any }[] = [];
  public cameraVisible= true;
  public saveToGallery=true;
  public isRecording=  false;
  public enableVideo=false;
  public fileName;
  public totalUpload
  public buttoninteraction =true
  public tasks: bgHttp.Task[] = [];
  public totalUploadpercent
  public progress
   lastEvent = "";
  constructor(private zone: NgZone,public location:Location,      public detector:ChangeDetectorRef,) {
        orientations.setOrientation("portrait")
        orientations.disableRotation();
        let video = getString("PHOTO")
        let videoName= getString("PHOTO")
        if(video && videoName){
            remove(video)
            remove(videoName)
        }
        bindingDist=this.detector.detectChanges;
    }
    ngOnInit(): void {}

    ngOnDestroy() {}

    public camLoaded(e: any): void {
        console.log('***** cam loaded *****', new Date().toString())
        this.cam = e.object as CameraPlus;
        let isPermmitCam=  this.cam.hasCameraPermission();
        if(!isPermmitCam){
            this.cam.requestCameraPermissions().then((permission)=>{
                console.log("[permission]",permission)
            }).catch((error)=>{
                console.log("[error]",error)
            })
        }else{

        }
    }

    public toggleCameraEvent(e: any): void {
    }
    public takePicFromCam(){
        this.cam.takePicture({width: 150, height: 150, keepAspectRatio: true, saveToGallery: false });
    }
    public photoCapturedEvent(e:any): void {
        new ImageSource().fromAsset(e.data as ImageAsset).then(result => {
            const base64String = result.toBase64String("png");
            console.log('PHOTO CAPTURED base64String!!!',base64String);
            setString("PHOTO",base64String);
            this.goToHome(base64String)
        });
    }
    public goToHome(event){
        ((this.isRecording==true)?this.cam.stop():this.isRecording=false)
        orientations.enableRotation();
        this.location.back()
    }
    public imagesSelectedEvent(e: any): void {
        new ImageSource().fromAsset((e.data as ImageAsset)[0]).then(result => {
            const base64String = result.toBase64String("png");
            console.log('IMAGES SELECTED EVENT!!!--3',base64String);
            setString("PHOTO",base64String);
            this.goToHome(base64String)
        });
    }
    public takeApphoto(event){
        console.log("[takeApphoto]",event.data)
        let isPermmitCam=  this.cam.hasCameraPermission();
        if(!isPermmitCam){
            this.cam.requestCameraPermissions().then((permission)=>{
                console.log("[permission-camera]",permission)
            }).catch((error)=>{
                console.log("[error]",error)

            })
        }else{
            this.cam.takePicture({
                width: 150, height: 150, keepAspectRatio: true, saveToGallery: false
            });
        }
    }
    public toggleFlash(){
        console.log("[toggleFlash]")
        let isPermmitCam=  this.cam.hasCameraPermission();
        if(!isPermmitCam){
            this.cam.requestCameraPermissions().then((permission)=>{
                let isFlashmode= this.cam.getFlashMode();
                console.log("[permission-isFlashmode]",isFlashmode)
                if(isFlashmode=="off"){
                    this.cam.toggleFlash();
                    console.log("[permission-isFlashmode-changed]",this.cam.getFlashMode())
                }
            }).catch((error)=>{
                console.log("[error]",error)
            })
        }else{
            console.log("[permission-camera-flash]",isPermmitCam)
            let isFlashmode= this.cam.getFlashMode();
            console.log("[permission-isFlashmode]",isFlashmode)
            if(isFlashmode=="off"){
                this.cam.toggleFlash();
                console.log("[permission-isFlashmode-changed]",this.cam.getFlashMode())
            }
        }
    }
    public openCamPlusLibrary(event){
        console.log("[openCamPlusLibrary]",event)
        let isPermmitCam=  this.cam.hasStoragePermissions();
        if(!isPermmitCam){
            this.cam.requestStoragePermissions().then((permission)=>{
                console.log("[permission-openCamPlusLibrary]",permission)
                this.cam.chooseFromLibrary();
            }).catch((error)=>{
                console.log("[error]",error)
            })
        }else{
            this.cam.chooseFromLibrary();
        }
    }
}

camera.component.html:

<ActionBar   title="" class="action-bar">
        <NavigationButton  icon="res://d" (tap)="goToHome($event)"></NavigationButton>
</ActionBar>
<StackLayout row="1" rows="auto, auto, auto" verticalAlignment="top" style="margin-top: 15;">
    <CameraPlus
    debug="true" showFlashIcon="true"
    [height]="size" enableVideo="enableVideo"
        galleryPickerMode="single"    confirmPhotos ="false"
        showToggleIcon="true" saveToGallery="false"
        showImages="false" showCaptureIcon="false"
        showVideos= "false"showGalleryIcon="false"
        (loaded)="camLoaded($event)" (toggleCameraEvent)="toggleCameraEvent($event)"
        (photoCapturedEvent)="photoCapturedEvent($event)"(imagesSelectedEvent)="imagesSelectedEvent($event)"
        >
    </CameraPlus>
</StackLayout>
 <GridLayout rows="*,*">
    <GridLayout row="2" rows="auto, auto" verticalAlignment="bottom" style="margin-bottom: 15;">
         <GridLayout    rows="auto, auto" columns="*,*,*">
            <StackLayout   class="btn-img" col="0"  orientation="horizontal"horizontalAlignment="center" (tap)="takeApphoto($event)"  >
                <Image   class="img" src="res://camera"  width="40%" height="100%" ></Image>
            </StackLayout>
            <StackLayout   class="btn-img"  col="2" orientation="horizontal"horizontalAlignment="center"(tap)="openCamPlusLibrary()" >
                <Image  class="img" src="res://images_regular"  width="40%" height="100%"   horizontalAlignment="center"></Image>
            </StackLayout>
        </GridLayout>
    </GridLayout>
</GridLayout>

logcatNokia.txt logcatSamsung.txt

calleja23 commented 3 years ago

removing android:hardwareAccelerated="false" from my manifest