canvas

Javascript changing image color IndexSizeError: Index or size is negative or greater than the allowed amount

橙三吉。 提交于 2020-01-16 13:21:09
问题 I am writing a javascript code where image changes color specified by a user.. the code is complete from my side.. but strangely mozilla throw the error IndexSizeError: Index or size is negative or greater than the allowed amount when cleared the cache and next time it runs good.. on chrome it does not run at all .. it says Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': the canvas has been tainted by cross-origin data. Im not sure what seems to be the

How to add a fade effect to only certain elements on a html canvas

老子叫甜甜 提交于 2020-01-16 13:06:29
问题 I have a canvas with multiple circles in different colours and I want add a fade out effect only to some circles. The effect is only applicable to the ones in red and green. The code is as follows function drawPiece(pieceX, pieceY, color) { if (color === "rgba(0,0,0,1)" || color === "rgba(255,255,255,1)"){ ctx.beginPath(); ctx.fillStyle = color; ctx.arc(pieceX, pieceY, 50, 0, 2 * Math.PI, false); ctx.fill(); ctx.lineWidth = "4"; ctx.strokeStyle = "rgba(0,0,0,1)"; ctx.stroke(); ctx.closePath()

Invert X and Y coordinates on HTML5 canvas

[亡魂溺海] 提交于 2020-01-16 12:04:13
问题 I am working on an interface that has a HTML5 canvas on it, and I need to invert the X and Y coordinates when you select a position. I thought that subtracting the width of the canvas from the selected X position, and subtracting the height of the canvas from the selected Y position would invert the coordinates, but it is doing some very weird things. The X and Y coords that log when you click in the top left corner of the canvas are X:324,Y:483 but theoretically, they should be X:650,Y:587 ,

Phonegap camera draw on canvas distorted

耗尽温柔 提交于 2020-01-16 11:25:10
问题 I'm using Phonegap Camera Plugin to draw the captured image on a Canvas. <canvas id="canvas"></canvas> And the JS: var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; var x = 0; var y = 0; var width = window.innerWidth; var height = window.innerHeight; var imageObj = new Image(); imageObj.onload = function() { context.drawImage(imageObj, x, y, width, height); }; imageObj.src = imageURI;

js canvas white line between 2 objects

一笑奈何 提交于 2020-01-16 10:38:04
问题 enter image description hereI'm having a problem with my graphic objects on canvas. My Rectangle consists out of two triangles. But when I fill the path of both triangles a little white line in between of them occurs. It's on the diagonal of the rectangle. s.initQuadrangle(new Point3D([100, 100, 0]), new Point3D([200, 100, 0]), new Point3D([200, 200, 0]), new Point3D([100, 200, 0])); The points are not floats as you can see. 来源: https://stackoverflow.com/questions/50518178/js-canvas-white

3.canvas与svg的区别

主宰稳场 提交于 2020-01-16 10:36:42
canvas是通过javascript来绘制的2D图形 canvas是控制像素来渲染的 一旦渲染完成,浏览器就不会关注了,如果位置发生变化,整个场景就需要重新绘制 <canvas id="mycanvas" width="500" height="300" ></canvas> <script type="text/javascript"> var c=document.getElementById("mycanvas"); var cxt=c.getContext("2d"); cxt.fillStyle="#FF0000"; cxt.fillRect(0,0,150,75); // 画了一条线 cxt.moveTo(160,0) cxt.lineTo(160,90) cxt.stroke() // 画一个圆 cxt.fillStyle="#FF0000" cxt.beginPath(); cxt.arc(200,100,15,0,Math.PI*2,true); cxt.closePath(); cxt.fill(); // 图像 var img=new Image() img.src="./video/QQ图片20190529164332.jpg" cxt.drawImage(img,100,100) </script> Svg是使用xml描述的2D图形 也就意味着 svg

[JavaScript] Canvas中ImageData

喜你入骨 提交于 2020-01-16 10:35:03
ImageData 对象 ImageData 对象中存储着canvas对象真实的像素数据,它包含以下几个只读属性: width 图片宽度,单位是像素 height 图片高度,单位是像素 data Uint8ClampedArray 类型的一维数组,包含着RGBA格式的整型数据,范围在0至255之间(包括255)。 data属性返回一个 Uint8ClampedArray ,它可以被使用作为查看初始像素数据。每个像素用4个1bytes值(按照红,绿,蓝和透明值的顺序; 这就是"RGBA"格式) 来代表。每个颜色值部份用0至255来代表。每个部份被分配到一个在数组内连续的索引,左上角像素的红色部份在数组的索引0位置。像素从左到右被处理,然后往下,遍历整个数组。 Uint8ClampedArray 包含高度 × 宽度 × 4 bytes数据,索引值从0到( 高度 × 宽度 ×4)-1 例如,要读取图片中位于第50行,第200列的像素的蓝色部份,你会写以下代码: blueComponent = imageData.data[((50-1)*imageData.width + (200-1))*4 - 1 + 3]; 根据行、列读取某像素点的R/G/B/A值的公式: imageData.data[((行数-1)*imageData.width + (列数-1))*4 - 1 + 1/2/3

unity 获取UGUI中的Text字的坐标

微笑、不失礼 提交于 2020-01-16 09:10:43
using System.Collections; using UnityEngine; using UnityEngine.UI; public class TextMoveHelper : MonoBehaviour { public Text textComp; public Canvas canvas; public Text text; public Vector3 GetPosAtText(Canvas canvas, Text text,string strFragment) { int strFragmentIndex = text.text.IndexOf(strFragment);//-1表示不包含strFragment Vector3 stringPos = Vector3.zero; if (strFragmentIndex>-1) { Vector3 firstPos = GetPosAtText(canvas, text, strFragmentIndex + 1); Vector3 lastPos= GetPosAtText(canvas, text, strFragmentIndex+strFragment.Length); stringPos = (firstPos + lastPos) * 0.5f; } else { stringPos=

How to draw line between points using click event handler?

[亡魂溺海] 提交于 2020-01-16 07:27:10
问题 I'm using a event handler on a HTML canvas to track the coordinates of where a user clicks, and my idea is to connect coordinates together with a line. The code below creates an Array and keeps a list of coordinates within the canvas element that the user has clicked on, and also contains logic to draw a line between the currently clicked point and the point that's been previously clicked on. The problem I'm encountering is that, no matter how many times I click, even though my Array is being

Android 自定义 view(三)—— onDraw 方法理解

吃可爱长大的小学妹 提交于 2020-01-16 06:42:12
前言: 上一篇已经介绍了用自己定义的属性怎么简单定义一个view《 Android 自定义view(二) —— attr 使用 》,那么接下来我们继续深究自定义view,下一步将要去简单理解自定义view的一个比较重要的方法 onDraw(Canvas canvas) ,在探究 onDraw方法之前,我们必须先深入了解两个类Paint和Canvas 。 第一:认识Paint 在探究onDraw之前首先必须要认识两个类,这里给出非常不错的两个资料参考网站,我也是从这里得到想要知道的东西,简单的说这下面几篇文章已经够我们喝一壶了,这里我就不再献丑了 http://www.apihome.cn/api/android/Paint.html http://www.cnblogs.com/aibuli/p/efef9d774df97c553a8a0c0c3495ba35.html?utm_source=tuicool&utm_medium=referral http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1105/1907.html http://blog.csdn.net/harvic880925/article/details/39080931 第二:认识Canvas Canvas类简单理解就是表示一块画布