更新记录
1.0.0(2026-08-12)
- 初始发布:涂鸦/文字/箭头/图形/标记/裁剪/旋转/翻转/撤销重做/合成导出
平台兼容性
uni-app(5.23)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | √ | - | - | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - | - | - | - |
wc-image-annotator 图片标注组件
一个功能完整、高性能的 uni-app 图片标注/编辑器 组件,支持涂鸦、文字、箭头、图形、标记、裁剪、旋转、翻转,并把底图与标注合成导出为图片文件。
兼容:微信小程序(完整)/ H5(尽力)/ App(尽力)。零第三方依赖(仅依赖 Vue3 + uni-app 原生 API),可直接作为 uni-app 插件市场插件发布。
功能特性
- 涂鸦 / 手写笔迹(可调粗细、颜色)
- 文字标注(可调字号、颜色、字重)
- 箭头、圆圈、方框、三角(拖拽画出)
- 多种元素标记(点击放置)
- 裁剪(多比例预设 + 自由裁剪 + 旋转 + 水平/垂直翻转)
- 整体旋转(90° 步进、带缓动动画)
- ↩ ↪ 撤销 / 重做(历史栈上限 50)
- 保存:合成底图与标注,高清导出(微信小程序通过 canvas 2d 导出)
安装
将 wc-image-annotator.vue、enums.ts、index.ts 拷贝到你的项目(推荐放在 components/wc-image-annotator/ 下)。
easycom 方式(推荐):在 pages.json 的 easycom 配置中声明:
{
"easycom": {
"autoscan": true,
"custom": {
"^wc-image-annotator$": "@/components/wc-image-annotator/wc-image-annotator.vue"
}
}
}
手动引入方式:
import WcImageAnnotator from '@/components/wc-image-annotator/wc-image-annotator.vue';
基本用法
<template>
<view class="page">
<wc-image-annotator
:image-url="imageUrl"
@cancel="onCancel"
@save="onSave"
@change="onChange"
/>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import WcImageAnnotator from '@/components/wc-image-annotator/wc-image-annotator.vue';
import type { AnnotationItem } from '@/components/wc-image-annotator';
const annotatorRef = ref<InstanceType<typeof wc-image-annotator> | null>(null);
const imageUrl = ref('https://example.com/a.jpg');
const onCancel = () => console.log('取消');
const onSave = (tempFilePath: string, annotations: AnnotationItem[]) => {
console.log('导出文件:', tempFilePath, '标注:', annotations);
};
const onChange = (annotations: AnnotationItem[]) => console.log('标注变化', annotations);
</script>
<style scoped>
.page { height: 100vh; }
</style>
Props
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
imageUrl |
string |
— | ✅ | 待标注图片地址(本地或网络路径) |
exportFileName |
string |
'image_annotated' |
— | 导出文件名(不含扩展名,H5/App 端下载时用) |
isShowTopBar |
boolean |
true |
— | 是否显示顶部操作栏(撤销/重做/保存) |
isShowSave |
boolean |
true |
— | 是否显示顶部「保存」按钮 |
primaryColor |
string |
'#07c160' |
— | 主题色(用于保存按钮等) |
canEditImage |
boolean |
true |
— | 是否启用「系统编辑」(微信原生图片编辑器) |
Events
| 事件名 | 参数 | 说明 |
|---|---|---|
cancel |
— | 点击取消时触发 |
save |
(tempFilePath: string, annotations: AnnotationItem[]) |
点击保存成功,导出临时文件路径与标注列表 |
change |
(annotations: AnnotationItem[]) |
标注列表变化时触发(新增/移动/删除/撤销/重做等) |
组件方法(通过 ref 调用)
| 方法 | 返回 | 说明 |
|---|---|---|
export() |
Promise<string> |
合成底图与标注导出,返回临时文件路径 |
getAnnotations() |
AnnotationItem[] |
获取当前标注(图片本地坐标,浅拷贝) |
setAnnotations(list) |
void |
覆盖式回填标注(用于回显已保存的数据) |
reset() |
void |
清空所有标注与旋转,复位初始图片 |
save() |
void |
等价于点击顶部「保存」按钮,触发 save 事件 |
const annotatorRef = ref<InstanceType<typeof wc-image-annotator> | null>(null);
// 主动导出
const tempFilePath = await annotatorRef.value?.export();
// 回显标注
annotatorRef.value?.setAnnotations(savedAnnotations);
类型定义
组件相关的枚举、接口、常量统一从 @/components/wc-image-annotator(index.ts)导出:
import type { AnnotationItem, TextItem, ArrowItem } from '@/components/wc-image-annotator';
import { AnnotateTool, MarkerKind, ShapeKind } from '@/components/wc-image-annotator';
标注坐标说明
所有标注的坐标均为 图片本地坐标(相对图片原始左上角,单位像素)。如需在其它画布 / 场景回放,请配合原图尺寸 imageInfo 使用。
| 标注类型 | interface | 说明 |
|---|---|---|
| 涂鸦 | PathItem |
type='path',points[] |
| 文字 | TextItem |
type='text',x/y/content/fontSize |
| 打勾/打叉 | ShapeItem |
type='check'\|'cross',x/y/size |
| 箭头 | ArrowItem |
type='arrow',x1/y1/x2/y2 |
| 方框 | BoxItem |
type='box',x1/y1/x2/y2 |
| 三角 | TriangleItem |
type='triangle' |
| 圆圈 | CircleItem |
type='circle' |
| Emoji 标记 | EmojiItem |
type='emoji',kind 为 MarkerKind |
平台注意事项
- 微信小程序:完整功能,导出使用
canvas type="2d"。 - 「系统编辑」工具:仅微信小程序支持(调用微信原生图片编辑器),其他端点击会提示。
- H5 / App:canvas API 实现有差异,旋转/裁剪/导出建议真机验证;导出文件在 H5 走下载、App 走临时文件。
- 组件内部使用原生
uni.showToast/uni.showModal提示,不依赖任何第三方 UI 库。
Changelog
v1.0.0
- 初始发布:涂鸦/文字/箭头/图形/标记/裁剪/旋转/翻转/撤销重做/合成导出
- 解耦外部依赖,内置轻提示,支持直接作为独立插件使用
- 新增可配置 props 与
ref方法(export/getAnnotations/setAnnotations/reset/save) - 新增
index.ts类型/常量统一出口

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 516
赞赏 0
下载 12500524
赞赏 1940
赞赏
京公网安备:11010802035340号