PIXI 写一个字及图片保存(2)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>pixi</title>
<script src="../js/pixi.min.js"></script>
</head>
<body> <script type="text/javascript">
//Create a Pixi Application
let app = new PIXI.Application({width: 526, height: 526,antialias:true});
document.body.appendChild(app.view);
// 设置背景颜色
app.renderer.backgroundColor = 0xcccccc; // 更改画布大小
// app.renderer.autoResize =true;
// app.renderer.resize(256,256)
// app.renderer.width / app.renderer.height // 创建画笔
let graphics = new PIXI.Graphics(); // 填充颜色及画一个矩形区域
graphics.beginFill(0xcccccc);
graphics.drawRect(0,0,app.renderer.width,app.renderer.height);
graphics.lineStyle(14, 0xffd900); //边框色
// 初始坐标
var lastPoint= {x:0, y:0}; // 是否按下去
var isMouse =false; // graphics.buttonMode = true;
// 交互行为
graphics.interactive = true;
app.stage.addChild(graphics); // 绑定事件
graphics.on('mousedown' ,onmousedown);
graphics.on('mouseup' ,onmouseup);
graphics.on('mousemove' ,onmousemove);
graphics.on('mouseout' ,onmouseoutFun); function onmousedown(event){
console.log(event)
this.data = event.data;
var initPosition = this.data.getLocalPosition(this.parent); //获取鼠标移动的位置
console.log(initPosition.x +"-----"+initPosition.y); // 更新坐标点
lastPoint = initPosition;
isMouse = true; }
function onmouseup(){
isMouse = false;
this.data = null;
}
function onmouseoutFun(){
if(isMouse == true){
isMouse = false;
this.data = null;
console.log('移除')
} }
function onmousemove(event){
if(isMouse == true){ var newPosition = this.data.getLocalPosition(this.parent); //获取鼠标移动的位置
// console.log(newPosition) // 绘画线条
graphics.moveTo(lastPoint.x,lastPoint.y);
graphics.lineTo(newPosition.x, newPosition.y);
graphics.endFill();
// 更新坐标点
lastPoint = newPosition; } } // 保存图片
function downloadImg(){
const image = app.renderer.plugins.extract.image(graphics);
document.body.appendChild(image);
} </script>
<a href="../img/1.png" download="test">aaa</a>
</body>
</html>
存在问题:
当画笔宽度设置大,书写会有明显的锯齿。。。目前还没有处理。
PIXI 写一个字及图片保存(2)的更多相关文章
- canvas学写一个字
第一步:画一个米字格,先画一个矩形,再画中间的米字. <script> window.onload = function(){ var canvas = document.getEleme ...
- 使用iScroll和photoswipe写手机浏览图片的插件的几点经验
首先,当我知道我得到一个任务需要写一个在手机上能浏览图片的插件时,我第一想到了iScroll.它的左右滑动,上下滑动的效果在安卓手机上也能让用户有良好的体验,自己写也能方便控制. 我的需求是,插件要能 ...
- 24位和8位BMP图片保存纯C代码
BMP图片大家都知道,可以通过查看BMP图片结构使用纯C就可以打开,编辑,处理,保存图片.非常方便使用. 具体BMP结构可以参考:wingdi.h头文件.今天主要在进行删减代码,需要把多余的代码删除, ...
- 使用Emacs中的org-mode写cnblogs之图片插入
.title { text-align: center; margin-bottom: .2em } .subtitle { text-align: center; font-size: medium ...
- .NET压缩图片保存 .NET CORE WebApi Post跨域提交 C# Debug和release判断用法 tofixed方法 四舍五入 (function($){})(jQuery); 使用VUE+iView+.Net Core上传图片
.NET压缩图片保存 需求: 需要将用户后买的图片批量下载打包压缩,并且分不同的文件夹(因:购买了多个用户的图片情况) 文章中用到了一个第三方的类库,Nuget下载 SharpZipLib 目前用 ...
- canvas知识03:学写一个字案例
效果
- 2018-5-22-SublimeText-粘贴图片保存到本地
title author date CreateTime categories SublimeText 粘贴图片保存到本地 lindexi 2018-05-22 15:15:26 +0800 2018 ...
- php 获取远程图片保存到本地
php 获取远程图片保存到本地 使用两个函数 1.获取远程文件 2.把图片保存到本地 /** * 获取远程图片并把它保存到本地 * $url 是远程图片的完整URL地址,不能为空. */ functi ...
- 用qt代码怎样编写图片保存格式[qt4.6]
用qt代码怎样编写图片保存格式 qt提供了多个保存图片的接口,比较常用的接口如下 bool QPixmap::save ( const QString & fileName, const ch ...
随机推荐
- 数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation 标签: 图像处理MATLAB
实验要求: Zooming and Shrinking Images by Bilinear Interpolation Objective To manipulate another techniq ...
- c++ 切勿重新定义继承来的带缺省参数的函数
切勿重新定义继承来的带缺省参数的函数.我们知道,继承来的函数是virtual 的,至于原因在上一节中已经说明了,即“切勿重新定义父类non-virtual函数”.所以确切的描述应该是“切勿重新定义继承 ...
- p4322 [JSOI2016]最佳团体
传送门 分析 我们不难发现这是一棵树 于是01分数规划然后树上dp即可 代码 #include<iostream> #include<cstdio> #include<c ...
- EZOJ #79
传送门 分析 在经过若干次操作之后一定会产生一堆环 而我们又发现从一个点到另一个点实际可以经过所有环 于是问题就转换成了$k_1s_1 + k_2s_2 + ... + len = t$ 其中$s_i ...
- PartyLocation.get请求
1.PartyLocationDto:partyDto 2.PartyLocationConverter: 3.PartyDto:Public PartyDto 4.PartyLocationToPa ...
- Website开发前页面设计 Mockup的一些工具
这里介绍的Website开发前,页面设计的一些工具 1. Balsamiq (我们公司用的) https://balsamiq.com/download/ 2. Figma https://ww ...
- Markdown语法简介 | Markdown Tutorial
Markdown是一种轻量级标记语言,允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的HTML文档. 与Word相比,使用Markdown最大的好处是可以使人们将注意力集中与文字本身而非排版 ...
- JAVA基础语法动手动脑实践体会
一.运行EnumTest.java程序. public class EnumTest { public static void main(String[] args) { Size s=Size.SM ...
- 符合条件中用where 1=1影响效率以及having和where的区别
想当初我自己想出来用where 1=1的时候还高兴了一小会,毕竟把代码简化了许多.今天看到的书里面说会影响性能.摘要如下: 低效的“WHERE 1=1” 网上有不少人提出过类似的问题:“看到有人写了W ...
- angular 分页
http://jsfiddle.net/SAWsA/11/# <html xmlns:ng="http://angularjs.org" ng-app lang=" ...