drawimage

Using Web Workers for drawing using native canvas functions

*爱你&永不变心* 提交于 2019-11-27 12:48:56
问题 It's possible to send a CanvasPixelArray obtained via getImageData to a worker script, and let the worker script manipulate the pixels in its background thread, and eventually post the manipulated pixel array back. However, I'm using native canvas drawing functions, like drawImage . The drawImage calls are currently blocking the UI thread. This causes slow redraw of buttons, and a noticeable delay when clicking on a button, just to name a few drawbacks. (Edit: A small improvement can now be

Strange HTML5 Canvas drawImage behaviour

早过忘川 提交于 2019-11-27 12:07:03
问题 I am writing some code that uses HTML5 canvas. Generally it works well, but now I found a very strange behaviour. The weird thing is that it is consistent on different browsers, so must be that I understood the thing wrong... Despite the docs seem to say exactly what I am doing. Here is the code (it's an object method): MyCanvas.prototype.getElement = function() { var innerHtml = "<div></div>"; var elem = jQuery(innerHtml, { 'id' : this.viewId }); var canvas = jQuery("<canvas/>", { 'id' :

Combobox draw image on selected

ⅰ亾dé卋堺 提交于 2019-11-27 08:42:53
问题 I try to draw an image from a image list in a combobox when the item is selected. I am able to draw the image, but when the onSelctedIndexChanged event finish, i lost my image. My combobox already have the DrawMode.OwnerDrawFixed I have a ListImage control named ImageList with 10 pictures. For my short example i just need to draw in my combobox the image at position 1 of my ImageList, it's the reason why i get this.ImageList.Draw(g, 0, 0, 1 ); protected override void OnSelectedIndexChanged

canvas drawImage doesn't draw images the first time

[亡魂溺海] 提交于 2019-11-27 07:49:33
问题 I'm working on a simple JavaScript game using HTML5 canvas. It's a very typical game-loop setup involving: init() function that initializes objects to be used the playfield, randomizing some start x/y positions and similar setup tasks draw() function that draws all the game objects, including some simple canvas shapes and a few images setInterval to call draw every 25 milliseconds While getting this project started, I had the setInterval call at the end of the init() function, so it'd just

How can I draw an image from the HTML5 File API on Canvas?

…衆ロ難τιáo~ 提交于 2019-11-27 06:37:12
I would like to draw an image opened with the HTML5 File API on a canvas. In the handleFiles(e) method, I can access the File with e.target.files[0] but I can't draw that image directly using drawImage . How do I draw an image from the File API on HTML5 canvas? Here is the code I have used: <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <script> window.onload = function() { var input = document.getElementById('input'); input.addEventListener('change', handleFiles); } function handleFiles(e) { var ctx = document.getElementById('canvas').getContext('2d'); ctx.drawImage(e.target.files[0],

draw 10,000 objects on canvas javascript

对着背影说爱祢 提交于 2019-11-27 04:00:07
问题 I need draw over 10,000 images (32x32 px) on canvas but over 2000 draws the performances is very bad. this is a little example: object structure {position:0} for(var nObject = 0; nObject < objects.length; nObject++){ ctx.save(); ctx.translate(coords.x,coords.y); ctx.rotate(objects[nObject].position/100); ctx.translate(radio,0); ctx.drawImage(img,0,0); ctx.restore(); objects[nObject].position++; } with this code I traslate the images around of a coordinates. What do you recommend to improve

draw 10,000 objects on canvas javascript

允我心安 提交于 2019-11-27 03:06:38
I need draw over 10,000 images (32x32 px) on canvas but over 2000 draws the performances is very bad. this is a little example: object structure {position:0} for(var nObject = 0; nObject < objects.length; nObject++){ ctx.save(); ctx.translate(coords.x,coords.y); ctx.rotate(objects[nObject].position/100); ctx.translate(radio,0); ctx.drawImage(img,0,0); ctx.restore(); objects[nObject].position++; } with this code I traslate the images around of a coordinates. What do you recommend to improve performance? update: i try layering but the performances worsens http://jsfiddle.net/72nCX/3/ I can get

Drawing PNG to a canvas element — not showing transparency

喜夏-厌秋 提交于 2019-11-27 03:04:15
问题 I'm trying to use drawImage to draw a semi-transparent PNG on a canvas element. However, it draws the image as completely opaque. When I look at the resource that's being loaded and load the actual PNG in the browser, it shows the transparency, but when I draw it on the canvas, it does not. Any ideas? Here's the code: drawing = new Image() drawing.src = "draw.png" context.drawImage(drawing,0,0); 回答1: Don't forget to add an event listener to the image's load event. Image loading is something

How does Java Graphics.drawImage() work and what is the role of ImageObserver

筅森魡賤 提交于 2019-11-27 02:35:47
问题 How should Java's drawImage() be used? I do not find the JDK documentation very forthcoming. For example all drawImage signatures require an ImageObserver but the documentation for this is not very helpful for new users. 回答1: You can get away with Graphics.drawImage(img, x, y, null) [or similar]. The ImageObserver parameter is a callback to inform you of the progress of the draw operation; and is really only useful if you're fetching the Image parameter asynchronously. To be clearer, if you

Uncaught Error: INDEX_SIZE_ERR

大憨熊 提交于 2019-11-27 01:40:24
问题 I am drawing on a canvas with the following line: ctx.drawImage(compositeImage, 0, 0, image.width, image.height, i, j, scaledCompositeImageWidth, scaledCompositeImageHeight); This code has executed error free on Safari, Chrome, Firefox (and even IE using google's excanvas library). However, a recent update to Chrome now throws the following error: Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 This code often positions part or all of the drawn image OFF the canvas, anyone got any idea what's