canvas

A reusable function to clip images into polygons using html5 canvas

家住魔仙堡 提交于 2020-01-01 14:07:07
问题 Guess the title of the post may need editing, but for now I don't know where the problems are. I have read pages and answers to similar questions, here and elsewhere. One Stack Overflow answer is especially close, but I don't understand it. I want a function, to draw polygons on canvas at desired coordinates and to fill them with some background image loaded from a file (large enough that no tiling is needed). Triangles would be fine for a test. Apparently I should use drawImage and clip, and

Creating a canvas on top of an SVG (or other image)

无人久伴 提交于 2020-01-01 12:44:07
问题 The reason for asking this question is because I want to be able to draw an arrow between two svg images. I want to use canvas to create the arrows, so firstly I generate the svgs then place a canvas on top of them to be able to draw the arrows. I've tried using style=... but haven't had any luck as everytime I add the canvas element it just pushes my svg images to another pl If there's no easy way to do this I'll just create arrows using SVG, I figured it would be more efficient to use

How to determine when a canvas has finished loading

╄→尐↘猪︶ㄣ 提交于 2020-01-01 12:00:10
问题 So I was making a rather large canvas that was filled with 1x1 pixels, and I wanted to make a loading screen for it. The problem after the loop filling the canvas finishes, it alerts that it has finished loading, but the canvas has not actually changed. I made a jsfiddle here to demonstrate. How do I actually find out when the canvas has actually loaded using javascript or Jquery, and what is causing this behavior? var ctx=document.getElementById('canvas').getContext('2d'); for(var x=1;x<600

Fastest way to iterate pixels in a canvas and copy some of them in another one

a 夏天 提交于 2020-01-01 11:57:09
问题 I'm into a 2D/3D graphic project and I'm facing a performance problem. My algorithm takes two images: a picture and the relative grayscale depth map. I have also an array of 10 canvases ("layers") initally blank. A note: all the images have the same dimension. I need to check every pixel X;Y of the depth map and, depending on its color value, access one of the 10 canvases and draw the X;Y pixel of the original image on it. Resulting algorithm is someting like: for (var y = 0; y < totalHeight;

Canvas - Image resize and copy into another

时光怂恿深爱的人放手 提交于 2020-01-01 10:15:33
问题 Is there a jQuery plugin or code with which I could resize an image (or canvas (with this image)) and copy that into another image (or canvas)? Picture #2 is a EDIT: Idea: Maybe make use of -moz-transform: scale(sx, sy) / -webkit-transform: scale(sx, sy) ? Or this Resizing an image in an HTML5 canvas 回答1: You can resize-and-copy an image or canvas into another canvas easily. context.drawImage(image, dx, dy, dw, dh) allows you to resize any image (or canvas) you want to draw as you draw it.

Draw a self intersecting polygon on the HTML Canvas

雨燕双飞 提交于 2020-01-01 09:54:34
问题 I'm looking for a way to draw a self intersecting polygon with holes, I'm using the HTML Canvas element. So given 5 points, I want to draw the red one below. This question is essentially the same thing. Note: I don't want to do this using line intersections and adding more points, the actual paths I will be using will be curved. 回答1: You can't draw the first pentagram with a single path in Canvas 2D - the fill rule being used there is even-odd and Canvas fills shapes with the non-zero winding

使用Canvas实现粒子连线效果

孤人 提交于 2020-01-01 09:51:16
看到别人网站上的画布特效,觉得特别炫酷,然后自己就在网上学习了一些Canvas的基础知识,附上链接: Canvas基础 然后就借鉴下大神的代码自己做了一个粒子线条特效,效果如下 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> <style> body { margin: 0; padding: 0; background: linear-gradient(to bottom, #000000 0%, #5788fe 100%); } canvas { width: 100%; height: 100%; } </style> </head> <body> <canvas></canvas> <script> //获取canvas元素,并给canvas设置大小 var can = document.querySelector("canvas"); can.width = window

How to draw a smooth curved line in WPF?

可紊 提交于 2020-01-01 09:22:51
问题 I have three known positions, and currently I am driving two lines like so: Line line = new Line { StrokeThickness = 3, Stroke = lineColor, X1 = MyX, Y1 = MyY, X2 = MyX, Y2 = MiddleY }; Graph.Children.Add(line); line = new Line { StrokeThickness = 3, Stroke = lineColor, X1 = MyX, Y1 = MiddleY, X2 = TargetX, Y2 = TargetY }; Graph.Children.Add(line); Here's the result: So, as you can see, this is almost what I want except that I want it to be more smoothed out, just a little bit. Now I'm

HTML5 Canvas changes colors of all lines [duplicate]

被刻印的时光 ゝ 提交于 2020-01-01 07:31:07
问题 This question already has an answer here : All html canvas shapes are given the color of the last object added (1 answer) Closed last month . I made a simple drawing app with HTML5 canvas. You click in two different positions to draw a line from one point to another. I also have two text input boxes where you can change the line thickness and color. Problem is, when I change the color of a line it changes all the previously drawn lines. This also happens when changing line thickness, but only

android open gl really slower than canvas?

China☆狼群 提交于 2020-01-01 06:52:05
问题 im testing the android SpriteMethodTest and on default settings canvas is getting 58fps while open gl is between 50-55fps, and the gap just gets larger with more sprites. I was under the impression that opengl is faster than canvas so is this wrong? or is their something wrong with my phone (htc desire)? http://code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest/ 回答1: It should be noted that SpriteMethodTest is not using OpenGL at maximum efficiency. Each sprite is being