canvas

Canvas inner stroke

旧城冷巷雨未停 提交于 2020-04-29 09:38:00
问题 I studied strokeStyle a bit but I cant find how to control the position of the stroke from inner/center/outer. It seems all stroke is outside the rectangle I draw. Is there anyway make the stroke be inner? (or even centered on the rectangle bounds)? Thanks 回答1: The default stroke do use centered stroke but there is unfortunately no parameter to control the alignment of the stroke so you would either have to calculate an offset value for the rectangle's position and size, or combine two

How to scale resize an image on a canvas

强颜欢笑 提交于 2020-04-21 04:38:01
问题 I am currently trying to make an image upload tool, which allows you to crop an image before uploading it as a profile image. The crop box is resizable, and whatever is within the bounds of the box is shown as a preview in a seperate canvas on the webpage. At the moment, I have the following code, which takes the area within the cropper on the first canvas (context) and places it on the second canvas (previewContext). function previewCroppedImage() { var max_height = 100; var max_width = 100;

ffmpeg: Render webm from stdin using NodeJS

柔情痞子 提交于 2020-04-10 05:59:31
问题 I'm having an issue trying to dump some jpeg frames created on the fly to ffmpeg and NodeJS in order to create a webm video. The script attempts to do these things: Fork a new ffmpeg process on initialization Render a canvas Once the data in canvas is updated, grab JPEG data from it. Pipe the JPEG data into the ffmpeg stdin. ffmpeg takes care of appending it on a webm video file. and this goes forever and ffmpeg should never stop It should be an always growing video to be broadcast live to

How can I make canvas drawing work on mobile

笑着哭i 提交于 2020-04-10 04:47:28
问题 My canvas drawing interface works perfectly on desktop but fails to work on iPhone. When I try to draw, it just makes a dot where my thumb goes. When I drag my thumb, there is no line and the page continues to scroll... Code: var clearButton = document.getElementById('doodle-bin'); var canvascontainer = document.getElementById('doodle-canvas-container'); var canvas = document.getElementById('doodle-canvas'); var context = canvas.getContext('2d'); var radius = (document.getElementById('doodle

How can I make canvas drawing work on mobile

≡放荡痞女 提交于 2020-04-10 04:47:11
问题 My canvas drawing interface works perfectly on desktop but fails to work on iPhone. When I try to draw, it just makes a dot where my thumb goes. When I drag my thumb, there is no line and the page continues to scroll... Code: var clearButton = document.getElementById('doodle-bin'); var canvascontainer = document.getElementById('doodle-canvas-container'); var canvas = document.getElementById('doodle-canvas'); var context = canvas.getContext('2d'); var radius = (document.getElementById('doodle

canvas流星月亮星星银河

本秂侑毒 提交于 2020-04-08 13:09:22
这是页面的特效,首先月亮直接出现,然后星星和银河渐渐的出现(一闪一闪),最后流星划过,留下完美的句点。 所有的动画都是通过帧来实现的。 星星的代码分为2部分,首先是随机生成星星,然后是绘制星星,最后是星星的帧动画。 随机生成星星代码: function newStar(num,width,height) { var stars = []; /// 恒星 for(var i = 0; i < num; i++) { var x = Math.round(Math.random() * width); var y = Math.round(Math.random() * height); //避开月亮 if(y > 100 && y <400) { if(x > width - 300 && x < width -250) { x = x - 100; } else if(x > width - 250 && x < width -200) { x = x + 100; } } var star = { x: x, y: y, r:Math.round(Math.random()*4), alpha:0,//Math.random(), valpha:(Math.random()/70)*(Math.random() > .5 ? -1 : 1),//随机+- 星星透明度改变加速度 }

网页背景动态连线动画效果的实现

不羁的心 提交于 2020-04-07 22:43:39
使用 canvas-nest.js 下载地址 : http://www.jfinalxueyuan.com/assets/js/canvas-nest.js 放在web下的js目录 在网页body最后添加代码 <script color="255,255,255" opacity='0.3' zIndex="-1" count="110" src="/js/canvas-nest.js" type="text/javascript"></script> 刷新网页,可看到以下效果 来源: oschina 链接: https://my.oschina.net/peaksoho/blog/3223429

音视频入门之如何绘制一张图片

烂漫一生 提交于 2020-04-06 10:35:59
Android 的音视频入门学习,首先了解一下绘制图片。在 Android 平台绘制一张图片,使用至少 3 种不同的 API,ImageView,SurfaceView,自定义 View作绘制图片。下面我以SurfaceView作重点来讲,为什么不用其他的来作例子,分析完SurfaceView就是知道为什么要用SurfaceView作例子。 SurfaceView 我们以下面几个点来了解SurfaceView SurfaceView 有那些相关类。 SurfaceView 有那些特点。 如何使用SurfaceView呢。 SurfaceView的优缺。 SurfaceView 在视频开发中应用在那里。 SurfaceView 其实是继承了View ,但与View又有一些区别,View是通过 onDraw(Canvas canvas)方法中的Canvas去绘制自身显示有界面上,而SurfaceView则不需要onDraw方法,有人会有些疑问,如果SurfaceView不需要实现onDraw方法怎么去绘制自身呢?其实View是在UI线程中绘制的,SurfaceView是在子线程中绘制的(即在一个子线程中对自己进行绘制)。在子线程中绘制怎么拿到canvas呢?下面我们去了解SurfaceView 有那些相关类。 SurfaceView 有那些相关类。 有三个重要的类,分别如下:

基于 HTML5 Canvas 的拓扑组件 ToolTip 应用

我的未来我决定 提交于 2020-04-06 07:38:45
前言 ToolTip 效果是网页制作中常见的使用特效。当用户将鼠标悬浮在某个控件上时,ToolTip 显示并向用户展示相应的提示信息;当鼠标离开时,ToolTip 隐藏。一般情况下,我们使用 ToolTip 只是显示一句话或几个字,其实我们还可以展示很多信息。而今天的重点则是通过 Hightopo 的 HT for Web 产品来制作多种样式的 ToolTip。 首页地址: https://www.hightopo.com/index.html 实现方式 HT 共有八种具有可配置 ToolTip 功能的的视图组件,分别是 ht.graph.GraphView、ht.graph3d.Graph3dView、ht.widget.ListView、ht.widget.PropertyView、ht.widget.TableView、ht.widget.TreeView、ht.widget.TreeTableView、ht.widget.Toolbar。 ht.Data 是 HT 最基础的数据类型,用户可将业务信息存储在 Data 对象属性上,目前提供了 Node、Edge、Column等子类应用于不同视图组件中,本文中会用 data 来统称。 显示基础的文本信息 首先建立一个视图组件(这里我们以 ht.graph.GraphView 为例,其余组件基本与之相同),通过调用组件的

OpenGL中 Canvas 性能分析

此生再无相见时 提交于 2020-04-06 02:02:44
本文将通过分析部分源码,描述 Android 里面的 Canvas 的大致实现。并且会对 Canvas 的性能做一定分析,提供对 Canvas 的使用建议。 GLES20RecordingCanvas 类 这个类是什么?为什么我从没用过? 我们来看看它的代码: class GLES20RecordingCanvas extends GLES20Canvas { ... } class GLES20Canvas extends HardwareCanvas { ... } public abstract class HardwareCanvas extends Canvas { ... } 它是不暴露给开发者的,所以我们也使用不了它。 而由 extends Canvas 可见,它是 Canvas 的一个实现类,所以应当也提供和 Canvas 一样的功能。那么它在哪里被使用了呢? 它是在 Android framework 源码处的,我们可以自定义一个 view,在 debug 时,断点到 @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } 就可以看到这个 canvas 的实例是 GLES21RecordingCanvas 了。 也就是说,几乎 Android 的所有 View