1

我正在尝试从本机脚本中的 imageAsset 获取图像数据,但我无法从我的图像中获取像素数据。我怎样才能做到这一点?

onCameraButtonTap(imageComponentRef: any, htmlDocRef: any): void {
    camera.takePicture().then((imageAsset) => {
        var image = new Image();
        image.src = imageAsset;
        imageComponentRef.src = imageAsset;
    }).catch((error) => {
        console.log(error);
    });
}

我的意思是这样的:image.getRGB(23,45),从坐标中获取像素 rgb 数据。

4

3 回答 3

0

对于NativeScript 中的Android :

您需要使用 android 原生位图和Color类来获取 RGB。

声明android在你的班级之上,例如

declare let android: any;

@Component({
....
{)

并在您的 takePicture 函数中添加以下代码

camera.takePicture().then((imageAsset) => {
        var image = new Image();
        image.src = imageAsset;
        imageComponentRef.src = imageAsset;
        const imagePath = imageAsset.android;
        const imageAndroidDrawable = android.graphics.drawable.Drawable.createFromPath(imagePath);
            const imageAndroidBitmap = android.graphics.BitmapFactory.decodeFile(imagePath);
            const pixel = imageAndroidBitmap.getPixel(23, 45);
            const redValue =  android.graphics.Color.red(pixel);
            const blueValue = android.graphics.Color.blue(pixel);
            const greenValue = android.graphics.Color.green(pixel);
    }).catch((error) => {
        console.log(error);
    });
于 2018-11-12T04:22:14.397 回答
0

目前还没有插件,不过好像是几行代码加上iOS / Android原生的api。

请参阅将Objective C / Java转换为 JavaScript的文档。

于 2018-11-11T18:55:13.510 回答
0

您可以使用 nativescript-bitmap-factory 从位图对象获取像素

var BitmapFactory = require("nativescript-bitmap-factory");

var colorSelected;

var bmp = BitmapFactory.asBitmap(imageAsset);

bmp.dispose(() => function {

     colorSelected = bmp.getPoint(23,45);

})
于 2018-11-13T07:21:56.987 回答