canvas

Save a html canvas image

拜拜、爱过 提交于 2019-12-30 03:34:08
问题 I know there is probably an answer already to this question but I haven't been able to find it yet and there is a deadline on my project. So I have made an html5 canvas and I would like to be able to do two things with one(or more) buttons. I would like the user to be able to save what he has just done by clicking on the save button and ideally I would like the image to be downloaded (as opposed to having to right click and "Save image as". This is what I have been able to do so far). I would

Save a html canvas image

爷,独闯天下 提交于 2019-12-30 03:33:06
问题 I know there is probably an answer already to this question but I haven't been able to find it yet and there is a deadline on my project. So I have made an html5 canvas and I would like to be able to do two things with one(or more) buttons. I would like the user to be able to save what he has just done by clicking on the save button and ideally I would like the image to be downloaded (as opposed to having to right click and "Save image as". This is what I have been able to do so far). I would

Drawing a circle on the canvas using mouse events

风流意气都作罢 提交于 2019-12-30 03:31:16
问题 I am trying to draw a circle using mouse on the canvas using mouse events, but it does not draw anything: tools.circle = function () { var tool = this; this.started = false; this.mousedown = function (ev) { tool.started = true; tool.x0 = ev._x; tool.y0 = ev._y; ctx.moveTo(tool.x0,tool.y0); }; this.mousemove = function (ev) { var centerX = Math.max(tool.x0,ev._x) - Math.abs(tool.x0 - ev._x)/2; var centerY = Math.max(tool.y0,ev._y) - Math.abs(tool.y0 - ev._y)/2; var distance = Math.sqrt(Math

HTML5 Game (Canvas) - UI Techniques?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 03:16:08
问题 I'm in the process of building a JavaScript / HTML5 game (using Canvas) for mobile (Android / iPhone/ WebOS) with PhoneGap. I'm currently trying to design out how the UI and playing board should be built and how they should interact but I'm not sure what the best solution is. Here's what I can think of - Build the UI right into the canvas using things like drawImage and fillText Build parts of the UI outside of the canvas using regular DOM objects and then float a div over the canvas when UI

How to draw transparent image with html5 canvas element

╄→尐↘猪︶ㄣ 提交于 2019-12-30 01:55:27
问题 I am targeting google chrome. Is it possible to draw transparent images on a canvas? By transparent I mean the drawing the entire image at something like 50% opacity. 回答1: The canvas element has a global alpha attribute that lets you apply partial transparency to anything you draw. 回答2: You can do this using the globalAlpha property, like this: <!DOCTYPE HTML> <html> <body> <canvas height="100" width="100" id="myCanvas"></canvas> <script> var canvas = document.getElementById("myCanvas"); var

Mouse coordinates don't match after Scaling and Panning canvas

时光怂恿深爱的人放手 提交于 2019-12-30 01:23:27
问题 I'm very new to javascript and canvas and I have a program that's supposed to detect elements animated on an elliptical path. It later on goes to form a tree.. But this is the basic structure that I've linked onto jsfiddle. It works fine without scaling or panning but as soon as I try to scale or Pan, the mouse coordinates go haywire. I tried following markE's advice from HTML5 canvas get coordinates after zoom and translate But i'm definitely doing something wrong and I've clearly not

How to generate an Image from imageData in javascript?

淺唱寂寞╮ 提交于 2019-12-30 00:14:52
问题 I would like to know if there is any way to create a new Image from imageData, which was previously obtained from a canvas element? I've searched for a solution, but they all seem to be drawing the result to a canvas. So basically I need a way to convert an ImageData object to Image directly, if its possible. 回答1: You can use toDataURL method in Canvas. It makes a image data as Data URI. var canvas = document.createElement("canvas"); canvas.width = 100; canvas.height = 100; var ctx = canvas

Masking shapes in HTML5 canvas?

怎甘沉沦 提交于 2019-12-30 00:07:44
问题 Apologies if this has been asked elsewhere but it's pretty hard to phrase as it is so I couldn't find anything. Is there any way to implement masks in canvas? For example, using shapes only (no images) I draw a house with a window. I also have a shape representing a person. I want that person to appear at the window - but obviously only so much as the window allows should be visible of the person. The rest would be masked. I thought about emptying the part of the house occupied by the window,

HTML5 Canvas Text Animating around circle

岁酱吖の 提交于 2019-12-29 09:49:27
问题 Updated what is wrong with the code? I know it doesnt rotate but why is the text screwy. Does anyone know why I am tearing my hair out trying to figure this out function showCircularNameRotating(string, startAngle, endAngle){ //context.clearRect(0, 0, canvas.width, canvas.height); context.font = '32pt Sans-Serif'; context.fillStyle = '#1826B0'; circle = { x: canvas.width/2, y: canvas.height/2, radius: 200 }; var radius = circle.radius, angleDecrement = (startAngle - endAngle/string.length-1),

Canvas and surfaceView example crash/freeze - Memory Leak?

此生再无相见时 提交于 2019-12-29 09:32:40
问题 http://www.helloandroid.com/tutorials/how-use-canvas-your-android-apps-part-1 At the end of this tutorial link for source code download is available. I downloaded the code and tried this example , It draws a kangaroo in the screen and within 1-2 minutes i get a crash/the application froze. I tried on Archos 70 Internet Tablet. "I would like to know the reason, or if some thing is wrong in this " Here is the LogCat 04-13 17:03:24.089: DEBUG/ondraw(2070): lefutott 04-13 17:03:24.097: DEBUG