Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-08-2012, 02:36 AM   PM User | #1
mrbean
New Coder

 
Join Date: Aug 2012
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
mrbean is an unknown quantity at this point
debugging canvas.

Hi!,

I am an javascript programmer, but beginner at working with the canvas API.

So I made an canvas with multiple images, not only in the viewport but also outside of the canvas.
I want to debug it, check how much pixels they are out of screen etc.

So I thougt I can convert the canvas to png/jpg. to see how big it is and how much extra pixels they use.

I tried but failed:
Uncaught TypeError: Object #<CanvasRenderingContext2D> has no method 'toDataURL'
Code:
Code:
    canvasFrame = document.getElementById('imageFrame');
    canvas = canvasFrame.getContext('2d');
yepnope("image-editor.js");
var img = game.canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');
An other option is to select al the images in the canvas and move it a couple of pixels to determinite the location of them. But I don't know how?

thanks anyway
mrbean is offline   Reply With Quote
Old 09-08-2012, 02:59 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
As the error message indicates, toDataURL doesn't apply to the 2d rendering object, but to the canvas itself - which you've called canvasFrame:

Code:
canvasFrame.toDataURL("image/png");
(It's the only significant method that actually applies directly to the canvas.)

BTW game.canvas looks wrong to me - you already have a direct reference to your variable 'canvas'; but perhaps you've named something else 'game.canvas'.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 09-08-2012, 10:54 PM   PM User | #3
mrbean
New Coder

 
Join Date: Aug 2012
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
mrbean is an unknown quantity at this point
It works thankss!

But it only show's whats in screen/on viewport.

I want to see the whole canvas, even if it doesn't fit in the canvas.
Any options?
mrbean is offline   Reply With Quote
Old 09-09-2012, 09:16 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Afaik (and would not be offended if I was proven wrong) the canvas is represented by its width and height (which is exactly what is visible on screen unless you cover parts of it with another element). The parts you paint outside of those borders are not part of the canvas and will never be taken into account, neither by toDataURL nor by getImageData. This is due to the fact that a canvas is a raster type of element. The "objects" drawn on the canvas are only sets of pixels. Pixels that would end up outside of the canvas will never exist.
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:46 AM.


Advertisement
Log in to turn off these ads.