Nativescript Camera和ImagePicker插件错误

时间:2019-04-03 18:44:21

标签: nativescript-angular nativescript-camera

我试图允许用户上传由相机或从照相馆新拍摄的照片,但在此之前,请预览它。 同时安装Camera和ImagePicker软件包时。返回的ImageAsset绑定不好(就像两个包都返回照片一样)。 iOS中似乎存在明显的冲突(尚未测试Android)

因此,基本上,我使用相机拍摄照片,然后将其绑定到图像元素。 安装完ImagePicker软件包之后。我是否不导入或使用ImagePicker都没关系,相机拍摄的照片会保存到iOS相册中,但不会与图像元素绑定(这意味着它不会显示)。同样,ImagePicker选定的图像不与图像元素绑定。没有引发任何错误。 在本机游乐场预览应用程序中。如果我在最新版本的iPhone 7 iOS中切换图像保存和写入权限。效果很好。

在安装nativescript-imagepicker之前和之后,尝试使用带有NativeScript-camera软件包的以下代码:

注意:this.itemImage [imageId](可以将imageId设置为0),只需将源图像与image元素绑定。

import { ItemEventData } from "tns-core-modules/ui/list-view"
import { Component, OnInit } from "@angular/core";
import { Image } from "tns-core-modules/ui/image";
import * as imagepicker from "../nativescript-imagepicker";
import * as camera from "../nativescript-camera";
import { ImageSource, fromFile, fromResource, fromBase64 } from "tns-core-modules/image-source";
import { fromObject, fromObjectRecursive, Observable, PropertyChangeData } from "tns-core-modules/data/observable";


@Component({
    selector: "Home",
    moduleId: module.id,
    templateUrl: "./home.component.html",
    styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
    foodTitle: string = "";
    foodDetails: string = "";

    public imageTaken;
    public saveToGallery: boolean = false;
    public keepAspectRatio: boolean = true;
    public width: number = 300;
    public height: number = 300;
    public imageId: number;
    public itemImage: Array<ImageSource> = new Array<ImageSource>(7);//string | Image = "https://play.nativescript.org/dist/assets/img/NativeScript_logo.png";

    onTakePhoto(imageId) {

        //1. Rearrange current photos
        //2. Take photo?
        //3. Get photo from library?
        //4. Adv. get photo from instagram?
        //5. Delete photo, and rearrange.

        let options = {
            width: this.width,
            height: this.height,
            keepAspectRatio: this.keepAspectRatio,
            saveToGallery: this.saveToGallery
        };

        camera.takePicture().
            then((imageAsset) => {
                //console.log("Result is an image asset instance");
                var image = new Image();
                image.src = imageAsset.nativeImage;
                this.itemImage[imageId] = image.src;    // or imageAsset.nativeImage;
                console.log("image path is: " + image);

            }).catch((err) => {
                console.log("Error -> " + err.message);
            });
    }

    constructor() {
    }

    ngOnInit(): void {
    }
}

在安装nativescript-imagepicker软件包之前,使用camera.takePhoto拍摄的照片将显示在预览应用程序的绑定图像元素中。 但是之后,就不会了。没有错误。

0 个答案:

没有答案