Results 1 to 2 of 2

Thread: Grabbing image from canvas

  1. #1

    Grabbing image from canvas

    Hey Guys,

    I have a scientific application in which I display to the user data that they may want to save and view at a later date. Everything they would need is drawn onto the gl canvas via texture overlays with varying transparencies. I was wondering if there was a good way to grab the image and save it somehow? I know that readPixels will return a pixel array from the canvas, but I cannot seem to get it to work:
    Code :
    		var buff = gl.readPixels(0, 0, 100, 100, gl.RGBA, gl.UNSIGNED_BYTE );
    Any help would be greatly appreciated .

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    12

    Re: Grabbing image from canvas

    try

    Code :
    var pixels = new Uint8Array(width * height * 4);
    gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

    you can also use

    var data = canvas.toDataURL();

Similar Threads

  1. Grabbing image from OpenGL via OpenCL
    By Arkh in forum OpenCL
    Replies: 6
    Last Post: 08-03-2010, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •