Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: canvas toDataURL

8 views
Skip to first unread message
Message has been deleted

Boris Zbarsky

unread,
Sep 3, 2007, 12:35:50 AM9/3/07
to
krithika wrote:
> Does xulrunner1.8.1.3 has support for canvas.toDataURL.?

Are you calling it from JavaScript?

If not, then no.

-Boris

krithika

unread,
Sep 3, 2007, 5:44:58 AM9/3/07
to

I have just embedded gecko in java application .From the
nsIDOMDocument I get nsIDOMHTMLCanvasElement's and the do a
drawWindow() and then use canvas toDataURL method.

nsIDOMDocument doc = win.getDocument();
nsIDOMNode iframe =
doc.getElementsByTagName("iframe").item(0);
nsIDOMNSHTMLFrameElement iframeelem =
(nsIDOMNSHTMLFrameElement)iframe.queryInterface(nsIDOMNSHTMLFrameElement.NS_IDOMNSHTMLFRA
MEELEMENT_IID);
nsIDOMWindow window=iframeelem.getContentWindow();

nsIDOMNode n =
doc.getDocumentElement().getElementsByTagName("canvas").item(0);
nsIDOMHTMLCanvasElement canElem =
(nsIDOMHTMLCanvasElement)
n.queryInterface(nsIDOMHTMLCanvasElement.NS_IDOMHTMLCANVASELEMENT_I
ID);

nsISupports support = canElem.getContext("2d");
nsIDOMCanvasRenderingContext2D context =
(nsIDOMCanvasRenderingContext2D)support.queryInterface(nsIDOMCanvasRenderingContext2D.
NS_IDOMCANVASRENDERINGCONTEXT2D_IID);

context.clearRect(0,0,600,800);
context.save();
context.scale(1,1);
context.drawWindow(window,0, 0, 600,500,"blue");
context.restore();

String url = context.getCanvas().toDataURL();

I could see the iframe window content getting drawn on the canvas.

Will this not work?.If yes why.

Thanks for your response.

regards,
Krithi

Boris Zbarsky

unread,
Sep 3, 2007, 11:43:57 AM9/3/07
to
krithika wrote:
> Will this not work?

It will not. toDataURL only works when called from JavaScript.

-Boris

0 new messages