Nativescript插件“ nativescript-camera-plus”:无法设置图片大小(宽度和高度)

时间:2019-05-15 15:17:16

标签: nativescript

您好,我使用“ nativescript-camera-plus”插件(Github上的插件:https://github.com/nstudio/nativescript-camera-plus)开发了本机应用程序和即时消息,甚至完全按照“选项接口”部分中的说明设置了参数(宽度和高度) :

cam.takePicture({ saveToGallery: true, confirm: false, keepAspectRatio: true, width: 1920, height: 1440 });

...该插件拍摄并保存图片,并以移动设备的屏幕分辨率除以2作为参考。示例:如果屏幕分辨率为1920,则该插件除以2并在960中保存照片。我需要用我在代码的选项(参数)中确定的宽度和高度大小来保存照片。有人可以帮我吗?

我的代码:

exports.takePicFromCam = function (args) {
    cam.requestCameraPermissions().then(function () {
        if (!cam) {
            cam = new CameraPlus();
        }
        cam.takePicture({ saveToGallery: true, confirm: false, keepAspectRatio: true, width: 1920, height: 1440 });

    });
}

cam.on(CameraPlus.photoCapturedEvent, function (args) {

    fromAsset(args.data)
        .then(function (res) {
            var preview = topmost().getViewById('testImagePickResult');

            var picture = res;

            var matrix = new android.graphics.Matrix();
            matrix.postRotate(180);

            var imagemfinal = android.graphics.Bitmap.createBitmap(picture.android, 0, 0, picture.android.getWidth(), picture.android.getHeight(), matrix, true);

            preview.src = imagemfinal;

            var novonomedafoto = new Date().getTime();

        });

    imagemsource = page.getViewById("testImagePickResult").imageSource;

    const folderDest = fileSystemModule.knownFolders.currentApp();
    const pathDest = fileSystemModule.path.join(folderDest.path, "photos/" + novonomedafoto + ".jpg");
    const saved = imagemsource.saveToFile(pathDest, "jpg");
    if (saved) {
        console.log("Image saved successfully!");
    }

});

exports.onNavigatingTo = onNavigatingTo;

1 个答案:

答案 0 :(得分:0)

该插件不会以您建议的宽度和高度写入文件,而是仅返回调整后的图像资产(data),该资产包含具有您的宽度和高度规格的位图。

data.getImageAsync((bitmap, error) => {
  // Use `bitmap` (android.graphics.Bitmap)
});