canvas

HTML5 canvas

可紊 提交于 2020-01-25 01:05:51
canvas元素: 是HTML5新增的专门用来绘制图形的元素。canvas元素是一块无色透明的区域,它只是一个容器,本身不具备绘制的功能,开发者通过javascript脚本在区域上实现任意绘图。并不是所有浏览器都支持canvas元素。 camvas只有两个可选的属性width、height,如果不设置,则默认width为300,height为150,单位都是px。也可以使用css属性来设置宽高,但是如果宽高属性和初始比例不一样,会出现扭曲,所以建议不要使用css属性来设置宽高。 <body> <canvas id=”mycanvas” width=”” height=””> 您的浏览器不支持canvas元素,请更新或更换您的浏览器。 //替代内容,如果浏览器不支持canvas元素,会显示替代内容。如果支持,会忽略替代内容,正常渲染canvas元素。 </canvas> </body> 步骤: 在html5页面的 <body></body> 元素中添加 <canvas></canvas> 元素 <canvas id=”mycanvas” width=”” height=””></canvas> 使用id寻找页面中的canvas元素 window.onload=function(){ var canvas =document.getElementById(“mycanvas”); }

How to allow cross-origin access to imgs and canvases?

柔情痞子 提交于 2020-01-24 22:54:07
问题 I have problem with this code: var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH); Error from Google Chrome console is: Unable to get image data from canvas because the canvas has been tainted by cross-origin data. It's because i have run this site on the domain1.com, img src is on the domain2.com and later i want to set new src with a local (modified) data (as below), i think. return canvas.toDataURL(); I have tried many ways to allow cross-origin access, but nothing works: if

Trying to make hmac-sha256 work with Powershell for Canvas API

↘锁芯ラ 提交于 2020-01-24 22:49:11
问题 I was appointed the task of making a process in which a PowerShell script needs to make a call to Canvas servers in order to get data out of it for other uses that are outside the scope of this question. The first thing I did was research how the Canvas API actually works. I eventually found this post holds everything I think I should know about the API. The API requires an HMAC SHA 256 hash. I have decided to reverse engineer his the writer's code that makes the hash in order to make the

Javascript: Setting img src with absolute path

瘦欲@ 提交于 2020-01-24 21:26:42
问题 I am trying to manually set the img src to a path on the filesystem, and then I want to draw that image on a canvas. I am using: var curr_canv = document.getElementById('c_main').getContext('2d'); var img = new Image(); img.width = 525; img.height = 400; img.src = "..\AAAA\BBBB\CCCC\myimage.jpg"; curr_canv.drawImage(img,0,0); But nothing is drawn on the canvas after I do this. Any thoughts? 回答1: You need to set the path to an absolute path within your webserver . Javascript in the browser has

Best way to write thousands of strokes in WPF canvas

牧云@^-^@ 提交于 2020-01-24 21:14:08
问题 I have to implement writing by touch on Wacom tablet ( like on paper) and I need to render up to 200 strokes per second in WPF Canvas. The problem is that after about 20s of constant writing it gets a bit laggs and the laggs grows. I store all strokes in HashSet . I thought about taking screen shoot when HashSet contains over 600 elements and set it as a background image and clear the HashSet, but after ~30 screen shoots it gets a bit blurred. Do you have any idea how to make it better? 回答1:

Image Preloading in Canvas

我与影子孤独终老i 提交于 2020-01-24 20:56:25
问题 I'm drawing an Image on the canvas using the drawImage function. This is how Im setting the src property of the image: var img = new Image(); // Create new Image object img.src = 'test.php?filename=myfile.jpg' and then oCanvas.width = 600; oCanvas.height = 400; oContext.drawImage(img, 0, 0, 600, 400); The problem is that if the src isn't set then I get the foll error:" uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE)

Flutter: How to paint an Icon on Canvas?

僤鯓⒐⒋嵵緔 提交于 2020-01-24 20:37:08
问题 I'm using a CustomPainter to draw in Flutter like this: @override void paint(Canvas canvas, Size size) { canvas.drawRect(...); canvas.drawImage(...); ... } How to draw an Icon on canvas ? 回答1: Create a Paragraph containing the code point in the correct font, style it as needed, then draw it. final icon = Icons.add; var builder = ui.ParagraphBuilder(ui.ParagraphStyle( fontFamily: icon.fontFamily, )) ..addText(String.fromCharCode(icon.codePoint)); var para = builder.build(); para.layout(const

Flutter: How to paint an Icon on Canvas?

断了今生、忘了曾经 提交于 2020-01-24 20:37:05
问题 I'm using a CustomPainter to draw in Flutter like this: @override void paint(Canvas canvas, Size size) { canvas.drawRect(...); canvas.drawImage(...); ... } How to draw an Icon on canvas ? 回答1: Create a Paragraph containing the code point in the correct font, style it as needed, then draw it. final icon = Icons.add; var builder = ui.ParagraphBuilder(ui.ParagraphStyle( fontFamily: icon.fontFamily, )) ..addText(String.fromCharCode(icon.codePoint)); var para = builder.build(); para.layout(const

手写经典游戏 - FlappyBird

一笑奈何 提交于 2020-01-24 13:10:00
目录 一、FlappyBird简介 二、技术铺垫 1. canvas(画布) 2. 基于setInterval的动画实现 三、代码实现 1. 定义画布 2. 初始化参数 3. 首绘 4. 启动游戏 5. 连续的帧计算 总结 一、FlappyBird简介 FlappyBird(飞扬的小鸟)是由越南独立游戏开发者Dong Nguyen所开发的一款经典小游戏,如果你没有听说过这款游戏,那么请看下图: 我想大部分人都有一种熟悉的感觉吧。 这款游戏最初发行于移动端,后来又出现了web版的FlappyBird,技术上主要基于HTML5的canvas(画布)及其相关api。今天我们就要揭秘web端一个简单版本的FlappyBird,它仅有一百多行代码,但对我们了解canvas游戏开发却大有帮助。 温馨提示 :本游戏除了使用HTML5的canvas标签外,所有代码都是基于原生js的,所以你不会有任何额外的学习负担,这将是一次原汁原味的前端游戏开发体验! 好了,让我们开始吧。 二、技术铺垫 本游戏所依赖的底层技术主要有两个,一个是canvas,另一个是基于setInterval的动画原理(这里也可以用HTML5的requestAnimationFrame来替代,它的性能更好,不过本文为了不增加学习负担,选择了经典的setInterval实现)。 1. canvas(画布)

How to draw a rectangular frame using JS around an image fragment

∥☆過路亽.° 提交于 2020-01-24 11:03:26
问题 The question is inspired by this topic. I know how to draw a rectangular frame around the selected image fragment. I also know how to implement a tooltip when hovering over a red frame. Below is my code with the result of what I want to get as a result .container { width:100vw; height:100vh; } .rect { fill:transparent; stroke:red; stroke-width:2; } <div class="container"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 768"