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 ...
随机推荐
- 触摸屏、X11去掉鼠标
cursor disable in X11 Last updated 8 years ago 摘自:http://www.noah.org/wiki/cursor_disable_in_X11 Whe ...
- oracle date 和 timestamp区别
在今天的工作中,学到了以下几个知识点: 一.date和timestamp 的区别 date类型是Oracle常用的日期型变量,他的时间间隔是秒.两个日期型相减得到是两个时间的间隔,注意单位是“天”.例 ...
- 第4章 jQuery中的事件和动画
4.1 jQuery中的事件 4.1.1 加载DOM jQuery就是用 `$(document).ready()方法来代替传统JavaScript的window.onload方法的. 1.执行时机 ...
- 关于setVisibility的几个常量
在xml文件中,view控件一般都会有android:visibility这个属性 android:visibility:gone|cisible|invisible 在代码中,可以通过方法setVi ...
- MVC中使用代码创建数据库(code first +mysql+EF)
1.新建一个mvc项目 2.安装mysql需要的几个文件 EntityFramework.MySql.Data(6.9.12)和MySql.Data.Entity (6.9.12) 这里有几点要注意 ...
- C#中控制线程池的执行顺序
在使用线程池时,当用线程池执行多个任务时,由于执行的任务时间过长,会导制两个任务互相执行,如果两个任务具有一定的操作顺序,可能会导制不同的操作结果,这时,就要将线程池按顺序操作.下面先给一段代码,该代 ...
- window 启用 windows 自动登录
启用 windows 自动登录 方案一: 1.运行命令:control userpasswords2 2.取掉复选框的钩: 方案二:(方案一无效的时候使用) 微软官网地址:https://suppor ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
Little Boxes Problem Description Little boxes on the hillside.Little boxes made of ticky-tacky.Littl ...
- Qt 学习之路 2(7):MainWindow 简介
Qt 学习之路 2(7):MainWindow 简介 豆子 2012年8月29日 Qt 学习之路 2 29条评论 前面一篇大致介绍了 Qt 各个模块的相关内容,目的是对 Qt 框架有一个高屋建 ...
- C语言值拷贝传递机制
当参数是常量,变量,或表达式时,传递的数据就是这些数据对象所具有的内容,这种方式称为数值参数传递方式(简称传值方式).如果函数调用时所传递的实参是数据对象在内存中的存储单元的首地址值,这种方式称为地址 ...