canvas

How to remove the clip of a region in html 5 canvas

无人久伴 提交于 2021-02-07 05:34:27
问题 I am working with clip() in canvas. I have made a region to clip() , as specified below this.svgRenderer.ctx.rect(positionX, positionY, Width, Height); this.svgRenderer.ctx.clip(); After few drawing on the same canvas, I am trying to remove the clip for that region by using save() and restore() . But I am making mistakes and can't get that. So suggest any other way to remove the clip for the specified region without using save() and restore() 回答1: .clip is a permanent context state change. It

Mouse position within rotated rectangle in HTML5 Canvas

大兔子大兔子 提交于 2021-02-07 03:57:32
问题 Rotation of rectangles within an html5 canvas is being stored in radians. In order to find whether subsequent mouse clicks are within any given rectangle, I am translating the mouse x and y to the origin of rotation for the rectangle, applying the reverse of the rotation to the mouse coordinates, and then translating the mouse coordinates back. This simply isn't working - mouse coordinates are not being transformed as expected (that is, not within the bounds of the original rectangle when

Mouse position within rotated rectangle in HTML5 Canvas

早过忘川 提交于 2021-02-07 03:57:18
问题 Rotation of rectangles within an html5 canvas is being stored in radians. In order to find whether subsequent mouse clicks are within any given rectangle, I am translating the mouse x and y to the origin of rotation for the rectangle, applying the reverse of the rotation to the mouse coordinates, and then translating the mouse coordinates back. This simply isn't working - mouse coordinates are not being transformed as expected (that is, not within the bounds of the original rectangle when

How to draw segment of a donut with HTML5 canvas?

人盡茶涼 提交于 2021-02-06 08:23:13
问题 As the title states. Is this possible? Edit: When i say doughnut I mean a top, 2D view Is the only option to draw a segment of a circle, then draw a segment of a smaller circle with the same origin and smaller radius over the top, with the colour of the background? That would be crap if so :( 回答1: You do it by making a single path with two arcs. You draw one circle clockwise, then draw a second circle going counter-clockwise. I won't go into the detail of it, but the way paths are constructed

Canvas getImageData returning incorrect data on certain mobile devices

人走茶凉 提交于 2021-02-06 07:55:24
问题 I am working on a canvas video player with some special features based on frames of the video. To overcome the unreliable timing in the video HTML5 tag the videos we are using have a barcode embedded in each frame indicating the current frame number. Using the canvas getImageData method I can grab the pixels and read the barcode to get the frame number. This works great and I have a JSFiddle demonstrating that it works (I couldn't get around CORS in this fiddle to serve the video to the

Converting a png/jpg to .ico in javascript

╄→гoц情女王★ 提交于 2021-02-05 12:30:42
问题 So i want a tool that generates a .ico file from a jpg/png. I have generated the jpg from a canvas using this code: var img = c.toDataURL("image/png"); document.write('<img src="'+img+'"/>'); Which takes from this canvas: <canvas id="myCanvas" width="16" height="16"> So the qustion is; is it possible to convert the generated png to a ico? 回答1: In Firefox you can do this directly from canvas: // Make ICO files (Firefox only) var ctx = c.getContext("2d"); ctx.arc(c.width>>1, c.height>>1, c

Is there a way to clear an element from a canvas without eliminating the others?

雨燕双飞 提交于 2021-02-05 11:27:25
问题 I' m building a page loader with canvas, and using the es6 classes... ALthough at the moment I can't make it work properly.. one of the reason is that I can't find a way to clear the canvas in progression. This is my code so far : class Loader { constructor (width, height) { this.width = width this.height = height } _init() { this._createCanvas() this._bindEvents() } // create canvas _createCanvas () { this.canvas = document.createElement("canvas") document.body.appendChild(this.canvas) this

Click events on complex canvas shapes without recourse to external libraries

有些话、适合烂在心里 提交于 2021-02-05 11:25:49
问题 I'd like to implement click detection for multiple complex shapes on a single canvas element similar to that as realized by CanvasRenderingContext2D.isPointInPath() . Obligatory example code below. HTML: <canvas id="canvas"></canvas> <p>In path: <code id="result">false</code></p> JS: const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); const result = document.getElementById('result'); ctx.beginPath(); ctx.moveTo(25, 25); ctx.lineTo(105, 25); ctx.lineTo(25,

WPF - How to get canvas position on mouse click independently of the resolution and resizing

北城以北 提交于 2021-02-05 11:12:47
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;

WPF - How to get canvas position on mouse click independently of the resolution and resizing

扶醉桌前 提交于 2021-02-05 11:12:01
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;