canvas

How to detect if html5 canvas is blank?

随声附和 提交于 2020-01-11 11:43:05
问题 I have a doodle application that saves an html5 canvas to an image in s3. I want to avoid saving blank (totally transparent) pngs if the user accidentally clicks "save" without having drawn anything. I found that even for a blank canvas the toDataURL() is never an empty string, but huge dump of data. This string appears to always remain the same value if no data is added to the canvas. So one way of detecting an empty canvas is to compare the submitted canvas data to this empty canvas data

How to detect if html5 canvas is blank?

ぐ巨炮叔叔 提交于 2020-01-11 11:42:12
问题 I have a doodle application that saves an html5 canvas to an image in s3. I want to avoid saving blank (totally transparent) pngs if the user accidentally clicks "save" without having drawn anything. I found that even for a blank canvas the toDataURL() is never an empty string, but huge dump of data. This string appears to always remain the same value if no data is added to the canvas. So one way of detecting an empty canvas is to compare the submitted canvas data to this empty canvas data

How to detect if html5 canvas is blank?

末鹿安然 提交于 2020-01-11 11:41:47
问题 I have a doodle application that saves an html5 canvas to an image in s3. I want to avoid saving blank (totally transparent) pngs if the user accidentally clicks "save" without having drawn anything. I found that even for a blank canvas the toDataURL() is never an empty string, but huge dump of data. This string appears to always remain the same value if no data is added to the canvas. So one way of detecting an empty canvas is to compare the submitted canvas data to this empty canvas data

Tainted HTML Canvas even with CORS headers

◇◆丶佛笑我妖孽 提交于 2020-01-11 11:30:08
问题 I'm trying to get the data URL for an image. The image is coming from a cross origin remote server, Wikipedia. I use this JavaScript to try to do it: # get the image const img = document.createElement('img') img.src = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Strychnine.svg/360px-Strychnine.svg.png' # don't send credentials with this request img.crossOrigin = 'anonymous' # now copy to a <canvas /> to get data URL const canvas = document.createElement('canvas') canvas.width =

drawImage doesn't work when I refer to an image in another javascript file

元气小坏坏 提交于 2020-01-11 11:29:09
问题 (I'll show the pure javascript below) I've got these two lines of code that are, in my mind, doing the exact same thing but one of them reports an error. This appears in a file named "Rendering.coffee". Here are the two lines (in coffeescript): ... ctx.drawImage(document.getElementById("bg"), 0, 0) #this works ctx.drawImage(root.resources.bg, 0, 0) #TypeError: Value could not be converted to any of: HTMLImageElement, HTMLCanvasElement, HTMLVideoElement. ... I assign root.resources.bg in

Create context menu using JQuery with HTML 5 Canvas

℡╲_俬逩灬. 提交于 2020-01-11 10:34:15
问题 I try to develop HTML 5 Canvas has context menu. When click for every image in Canvas, it will show context menu for each image. At there, I has only one canvas <canvas id="canvas" width=300 height=300></canvas> It will show all image when I draw. I try some jquery library context menu, It only support in case have more canvas (because it using class or id element for detect HTML element). Now I want using only 1 canvas, I had been detected click for each image in canvas but I don't know how

Poor performance of html5 canvas under firefox

随声附和 提交于 2020-01-11 10:13:24
问题 I have the following html5 code: <canvas id="myCanvas" width=600 height=600> </canvas> followed by some javascript: <script type="text/javascript"> <!-- var img = new Image(); img.addEventListener('load', function() { reDraw('', this); }, false); img.src = "wood.png"; function reDraw(canv, image) { var canvas = canv; if (canvas == '') { canvas = $("canvas"); } var size = canvas.attr("width"); var elem = canvas.get(0); if (!elem || !elem.getContext){ return; } var context = elem.getContext('2d

canvas学习笔记(上篇)-- canvas入门教程 -- canvas标签/方块/描边/路径/圆形/曲线

独自空忆成欢 提交于 2020-01-11 09:50:39
【上篇】 -- 建议学习时间4小时 课程共(上中下)三篇 此笔记是我初次接触canvas的时候的学习笔记,这次特意整理为博客供大家入门学习,几乎涵盖了canvas所有的基础知识,并且有众多练习案例,建议大家学习10~15个小时,里面的案例请挨个敲一遍,这样才能转化为自己的知识。 技术要求:有html/css/js基础。 canvas标签 <canvas>是一个图形容器,让我们在网页中绘制图形,很多人把它称为画布,使用canvas绘制图形就相当于在画布上画画一样,我们可以绘制非常炫酷的页面效果。 如下图这种: 上面的效果当然要后期才有能力编写了,现在我们先从简单的入手 直接看代码 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{margin: 0;padding: 0} canvas{border: 2px solid #a4e2f9;margin: 30px auto;display: block} </style> </head> <body> <canvas height="300" width="500" id="myCanvas"></canvas> </body> </html> 我们定义了一个canvas标签(用法和普通标签一样)

threejs canvas todataurl is blank

霸气de小男生 提交于 2020-01-11 09:27:12
问题 Okay, I know that canvas.toDataUrl() will produce an image in png format. However, when I try to get the image from http://threejs.org/examples/#webgl_lines_sphere. All I see is a black image on chrome. To replicate the steps - 1) Open dev console and select the canvas element. 2) canvas = $0 3) context = canvas.getContext('webgl', {preserveDrawingBuffer: true}) 4) img = canvas.toDataUrl() 5) document.write('<img src="'+img+'"/>') The image is blank. However, I tried with a different canvas

How to fix “canvas: trying to use a recycled bitmap error”?

拥有回忆 提交于 2020-01-11 08:37:07
问题 I'm creating a RecyclerView to show a Grid of pictures. When selecting one of them, it should open a new activity with a transition. I'm using Glide library to load the pictures and the transition looks awful because it reloads the picture in the new activity. So I had to save it in cache, and then use it for the transition. I have the code, but sometimes if the picture doesn't load, it throws a Canvas RuntimeException. This is the log: 07-03 15:19:58.633 28461-28461/jahirfiquitiva.project E