跳至主要內容

类: Image

约 808 字大约 3 分钟老猫

image.Image

代表图像对象的类,通过opencv的Matopen in new window构造。或者通过, decodeImage等函数从图片文件、链接、Base64中解析。

<://www.autojs.ccndex="-1"> 目录

属性

方://www.autojs.ccia-current="page" href="image.Image.html#pixel" tppabs="https://www.wuyunai.com/docs/v9/generated/classes/image.Image.html#pixel" class="router-link-active router-link-exact-active">pixelclip
  • clipSync
  • ://www.autojs.ccge" href="image.Image.html#resize" tppabs="https://www.wuyunai.com/docs/v9/generated/classes/image.Image.html#resize" class="router-link-active router-link-exact-active">resize
  • resizeSync
  • scale
  • scaleSync
  • rotate
  • rotateSync
  • grayscale
  • grayscaleSync
  • copy
  • copySync
  • toBitmap
  • detectAndComputeFeatures
  • recycle
  • ofBitmap
  • Constructors

    constructor

    new Image(mat: Matopen in new window)

    参数

    名称类型描述
    matMat

    属性

    _mat

    _mat


    _c4mat

    _c4mat?


    _onRecycledCallbacks

    _onRecycledCallbacks


    mat

    get mat(): Matopen in new window

    返回值

    Matopen in new window


    c4mat

    获取四通道(BGRA格式)的Mat对象。

    get c4mat(): Matopen in new window

    返回值

    Matopen in new window


    width

    获取图像的宽度。

    get width(): number

    返回值

    number


    height

    获取图像的高度。

    get height(): number

    返回值

    number


    convertToTargetColor

    private convertToTargetColor


    of_ARGB_8888_Bitmap

    private static of_ARGB_8888_Bitmap


    方法

    pixel

    获取图像在位置(x, y)处的颜色。若为三通道图像,则假设其为BGR格式;若为四通道图像,则假设其为BGRA格式;若为单通道图像,则假设其为灰度图。

    pixel(x: number, y: number): Color

    参数

    名称类型描述
    xnumber
    ynumber

    返回值

    Color

    示例

    "nodejs";
    const { loadImage } = require("image");
    async function main() {
        const img = await loadImage("https://picsum.photos/200/300");
        console.log(img.pixel(0, 0));
    }
    main();
    

    clip

    用给定的区域剪切图像,异步返回剪切后的图像。

    clip(rect: cv.Rect): Promise<Image>

    参数

    名称类型描述
    rectcv.Rect指定剪切区域

    Promise<Image>

    示例

    "nodejs";
    const cv = require("@autojs/opencv");
    const { loadImage } = require("image");
    async function main() {
        const img = await loadImage("https://picsum.photos/200/300");
        console.log(await img.clip(new cv.Rect(0, 0, 100, 100)));
    }
    main();
    

    clipSync

    用给定的区域剪切图像,同步返回剪切后的图像。

    clipSync(rect: cv.Rect): Image

    参数

    名称类型描述
    rectcv.Rect指定剪切区域

    返回值

    Image

    示例

    "nodejs";
    const cv = require("@autojs/opencv");
    const { loadImage } = require("image");
    async function main() {
        const img = await loadImage("https://picsum.photos/200/300");
        console.log(img.clipSync(new cv.Rect(0, 0, 100, 100)));
    }
    main();
    

    resize

    缩放图像,异步返回缩放后的新图像。

    resize(width: number, height: number, interpolation?: number): Promise<Image>

    参数

    名称类型描述
    widthnumber缩放后的宽度
    heightnumber缩放后的高度
    interpolation?number插值方式,默认为{@link cv.INTER_LINEAR}。可以为{@link cv.INTER_AREA}, {@link cv.INTER_CUBIC}, {@link cv.INTER_LANCZOS4}, {@link cv.INTER_LINEAR}, {@link cv.INTER_NEAREST}等。

    # 返回值

    Promise<Image>


    resizeSync

    缩放图像,同步返回缩放后的新图像。

    resizeSy://www.autojs.ccnumber, height: number, interpolation?: number): Image

    参数

    名称类型描述
    widthnumber缩放后的宽度
    heightnumber缩放后的高度
    interpolation?number插值方式,默认为{@link cv.INTER_LINEAR}。可以为{@link cv.INTER_AREA}, {@link cv.INTER_CUBIC}, {@link cv.INTER_LANCZOS4}, {@://www.autojs.ccR}, {@link cv.INTER_NEAREST}等。

    返回值

    Image


    toBitmap

    将图像转换为android的Bitmap对象。

    toBitmap(): android.graphics.Bitmap

    返回值

    android.graphics.Bitmap


    回收://www.autojs.cc后不应对本对象进行任何操://www.autojs.ccrong>detectAndComputeFeatures(options?: DetectAndComputeFeaturesOptions): Promise<ImageFeatures>

    参数

    ://www.autojs.cc="text-align:left;">类型描述
    options?DetectAn://www.autojs.ccions

    返回值

    Promise<ImageFeatures>


    recycle

    回收图像对象。回收后不应对本对象进行任何操作。

    recycle(): void

    返回值

    void


    ofBitmap

    将android Bitmap对象转为Image对象。若Bitmap为空或非Bitmap对象,则抛出异常。

    ofBitmap(bitmap: android.graphics.Bitmapopen in new window): Image

    参数

    名称类型描述
    bitmapandroid.graphics.Bitmap

    返回值

    Image