Skip to content

Tiny.js renderer-specific plugins for exporting content from a renderer

License

Notifications You must be signed in to change notification settings

ant-tinyjs/tinyjs-plugin-extract

Repository files navigation

tinyjs-plugin-extract

画布扩展,获取画布的:Image 对象、base64 格式的图片、像素值等等

查看demo

http://tinyjs.net/plugins/tinyjs-plugin-extract.html#demo

引用方法

起步

首先当然是要引入,推荐NPM方式,当然你也可以使用CDN或下载独立版本,先从几个例子入手吧!

1、最简单的例子

引用 Tiny.js 源码

<script src="https://gw.alipayobjects.com/os/lib/tinyjs/tiny/1.3.1/tiny.js"></script>
require('tinyjs-plugin-extract');
// 或者
// import * as extract from 'tinyjs-plugin-extract';

// 新建 App
const app = new Tiny.Application();
const texture = Tiny.Texture.fromImage('https://gw.alipayobjects.com/as/g/tiny/resources/1.0.0/images/logo.png');
const sprite = new Tiny.Sprite(texture);
texture.on('update', function () {
  const image = app.renderer.plugins.extract.image(sprite);
  console.log(image);
  //=> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsC..SuQmCC">
});

依赖

API文档

http://tinyjs.net/plugins/tinyjs-plugin-extract.html#docs

About

Tiny.js renderer-specific plugins for exporting content from a renderer

Resources

License

Stars

Watchers

Forks

Packages

No packages published