npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-canvas2image

v0.7.1

Published

Cordova canvas2image Plugin

Readme

cordova-plugin-canvas2image

zh-CN en

本项目基于 [email protected] 开发,本文档重点阐述其在 OpenHarmony(OHOS)系统中的具体应用。

简介

cordova-plugin-canvas2image 是 Harmony Cordova 生态系统中一款核心插件,提供高效、跨平台的 Canvas 转图片解决方案,支持将 HTML5 Canvas 元素导出为 PNG/JPG 格式并保存到设备本地,适配移动端图片处理场景,为开发者提供便捷的 Canvas 转图片及本地保存能力。

  • 跨平台适配:支持多平台 Canvas 元素转图片,兼容移动端使用场景

  • 多格式支持:可将 Canvas 导出为 PNG、JPG 两种常用图片格式

  • 本地保存:支持将转换后的图片直接保存到设备本地相册

  • 高效便捷:API 简洁易用,无需复杂配置,快速实现 Canvas 转图片功能

支持平台

  • Android:API 19 及以上(Android 4.4+)

  • iOS:10.0 及以上

  • OHOS:5.0+

下载安装

通过 hcordova CLI 即可快速安装插件,支持从 npm 仓库、GitCode 仓库获取,可指定平台和版本安装。

从 npm 安装(推荐)

# 使用 hcordova CLI 安装
# 安装 hcordova 命令化工具
npm install -g hcordova

# 全平台安装最新稳定版插件
hcordova plugin add cordova-plugin-canvas2image

指定版本安装

如需安装特定版本插件,执行以下命令:

# 安装特定版本(例如 1.0.0)
hcordova plugin add [email protected] --platform ohos

从 GitCode 仓库安装(开发版)

安装主分支最新开发版代码,仅为 OHOS 平台安装:

# 仅安装到 OHOS 平台,安装主分支最新代码
hcordova plugin add https://gitcode.com/CPF-Cordova/cordova-plugin-canvas2image.git --platform ohos

# 指定标签/分支安装
hcordova plugin add https://gitcode.com/CPF-Cordova/cordova-plugin-canvas2image.git@develop --platform ohos

离线安装(本地包)

适用于无网络环境,先下载插件包到本地,再执行离线安装:

# 下载插件包到本地(示例路径:~/Downloads/cordova-plugin-canvas2image)
# 执行离线安装
hcordova plugin add ~/Downloads/cordova-plugin-canvas2image --platform ohos

安装后验证

安装完成后,可通过以下命令验证插件是否成功添加到项目中:

# 查看已安装的插件列表,若包含本插件 ID 则表示插件已成功安装
hcordova plugin list

卸载

# Cordova CLI 全平台卸载
hcordova plugin remove cordova-plugin-canvas2image 

# 指定平台卸载
hcordova plugin remove cordova-plugin-canvas2image --platform ohos

约束与限制

  • 依赖插件:无强制依赖,插件集成后可直接使用,无需额外配置

  • 转换功能依赖 HTML5 Canvas 元素,需确保 Canvas 元素已正确渲染内容,否则可能导致转换失败

  • 图片保存功能需授予设备存储/相册权限,否则无法正常保存到本地

兼容性

支持:

| 项目 | 版本/信息 | |-----|--------| | SDK | API12+ | | IDE | DevEco Studio: 5.0+ | | ROM | 5.1+ | | Emulator | OpenHarmony 6.0+ |

在以下版本中已测试通过:

| 项目 | 版本/信息 | |-----|--------| | @cordova-ohos/ohos | 14.0.1-ohos-14.0.1 | | SDK | 5.0.0(12) | | IDE | DevEco Studio: 6.0.13.200 | | ROM | 5.1.0.120 SP3 | | Emulator | OpenHarmony 6.0.1(21) |

使用示例

// 将图片画入 canvas 后,保存图片到相册
function  savePhotoCanvas() {
    window.canvas2ImagePlugin.saveImageDataToLibrary(
        function(msg){
            document.getElementById("canvasInfo").innerHTML = msg;
            console.log(msg);
        },
        function(err){
            console.log(err);
        },
        document.getElementById('myCanvas')
    );
}

使用说明

插件暴露全局对象 window.canvas2ImagePlugin,核心功能为将 HTML5 Canvas 元素转换为图片并保存到设备本地,无需额外初始化操作,直接调用对应方法即可。

核心方法说明:saveImageDataToLibrary(successCallback, errorCallback, canvasElement),用于将指定 Canvas 元素转换为图片并保存到本地相册。

  • successCallback:保存成功的回调函数,接收保存成功的提示信息

  • errorCallback:保存失败的回调函数,接收错误信息

  • canvasElement:需要转换的 HTML5 Canvas 元素(需确保元素已渲染完成)

目录结构

cordova-plugin-canvas2image/
├── src/                          # 源代码目录
│   └── main/                     # 主要源代码
│       ├── cpp/                  # C++ 原生代码
│       │   └── Base64ToGallery/  # Base64 转图片模块
│       │       ├── Canvas2ImagePlugin.cpp  # Canvas 转图片功能的 C++ 实现
│       │       └── Canvas2ImagePlugin.h    # Canvas 转图片功能的头文件
│       └── ets/                  # ArkTS 代码(OpenHarmony API)
│           └── components/       # 组件目录
│               └── AlertDialog/  # 弹窗组件
│                   └── AlertDialog.ets    # 弹窗功能的实现
├── www/                          # Web 资源目录
│   └── Canvas2ImagePlugin.js     # JavaScript Canvas 转图片接口(Cordova 桥接层)
├── .gitignore                    # Git 忽略文件配置
├── LICENSE                       # 项目开源许可证
├── OAT.xml                       # OpenHarmony 审核配置文件
├── package.json                  # Node.js 包配置
├── plugin.xml                    # Cordova 插件描述文件(核心配置)
└── README.md                     # 项目说明文档

贡献代码

使用过程中发现任何问题都可以提 Issue ,当然也非常欢迎发 PR 共建。

许可证

本插件基于 Apache License 2.0 开源,详见 LICENSE 文件。

官方资源