html5-canvas

toDataURL's output is base64, how to reduce the uploading time and bandwidth of a factor 1/3?

我怕爱的太早我们不能终老 提交于 2020-01-16 18:05:06
问题 The goal of the following code is to compress the input file (2 MB JPG file => 500 KB file) and then upload it to server when submitting the <form> . When importing an image from a JPG file into a canvas, and exporting it with toDataURL with: function doit() { var file = document.getElementById('file').files[0], canvas = document.getElementById('canvas'), hidden = document.getElementById('hidden'), ctx = canvas.getContext("2d"), img = document.createElement("img"), reader = new FileReader();

toDataURL's output is base64, how to reduce the uploading time and bandwidth of a factor 1/3?

孤街醉人 提交于 2020-01-16 18:04:39
问题 The goal of the following code is to compress the input file (2 MB JPG file => 500 KB file) and then upload it to server when submitting the <form> . When importing an image from a JPG file into a canvas, and exporting it with toDataURL with: function doit() { var file = document.getElementById('file').files[0], canvas = document.getElementById('canvas'), hidden = document.getElementById('hidden'), ctx = canvas.getContext("2d"), img = document.createElement("img"), reader = new FileReader();

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()

Player movement in javascript with socket.io

徘徊边缘 提交于 2020-01-16 08:57:08
问题 Im currently making a html5 multiplayer game with socket.io. My problem is that i can only move my character in a straight line, while i also want to be able to move diagonal across my canvas. What i mean by this is if i press the 'a' and 'd' key, my character moves diagonally to the bottom right. With my current code my character only moves to the right or down. //client, how i capture my keyboard input. document.onkeydown = function(event){ console.log(`Keycode: ${event.which}`); if(event

Player movement in javascript with socket.io

一笑奈何 提交于 2020-01-16 08:57:05
问题 Im currently making a html5 multiplayer game with socket.io. My problem is that i can only move my character in a straight line, while i also want to be able to move diagonal across my canvas. What i mean by this is if i press the 'a' and 'd' key, my character moves diagonally to the bottom right. With my current code my character only moves to the right or down. //client, how i capture my keyboard input. document.onkeydown = function(event){ console.log(`Keycode: ${event.which}`); if(event

Loading multiple images with javascript

和自甴很熟 提交于 2020-01-16 05:29:05
问题 I am strugling to create a script to load multiple images for a game drawn on Canvas. The window seems to load without completing the load of all images. I've tried many ways but none of them seems to work. The function drawGameMenu() is called before the images are actually loaded and so the images are not drawn. If someone could help, I would be grateful. Here is my script, kind regards: var imageNames = ["menuImage", "resetScoreButton", "instructionsButton", "playButton", "dialogPanel",

Can't UPDATE a large image size that was INSERTed in the database in asp.net

谁说胖子不能爱 提交于 2020-01-16 04:59:15
问题 Here is the problem, when I insert an image (let's call it Data A) which is 1.32MB, it will be inserted successfully. But if I will insert again Data A(but it will update now because i used UPSERT, see my code), it will not be updated and it will result to connection time out. But when i insert another data (Data B) which is only 4KB, it will also be inserted successfully and if I will insert again into it(which is update), it will be updated successfully. What can I do? I cannot understand

Sketch.js pageX undefined error

╄→гoц情女王★ 提交于 2020-01-15 10:59:06
问题 I am using sketch.js by intridea in my phonegap application.It works allright with the modification case 'touchstart': if (this.painting) {//add this.stopPainting(); //add }//add this.startPainting(); break; by adding the above lines to the code.But I am getting a pageX undefined error which is crashing my app. 01-23 19:53:59.342: E/Web Console(31932): Uncaught TypeError: Cannot read property 'pageX' of undefined at file:///android_asset/www/js/external_libs/sketch.js:107 How to overcome this

NS_ERROR_FAILURE in Firefox on setting font of canvas inside a hidden iframe

只愿长相守 提交于 2020-01-15 03:22:07
问题 I am trying to create a text editor using a canvas . To place the cursor at the right position I need to calculate the width of every character. I am caching the width of each character on initial load. This works fine on Firefox when launched directly but throws an error ( NS_ERROR_FAILURE ) when launched inside an iframe whose parent is hidden. I've narrowed down this case in a fiddle here. Can anyone help me out with the cause of this issue? 回答1: You can't have an iframe set to display