Results 1 to 2 of 2

Thread: Accessing image data

  1. #1

    Accessing image data

    I have the following code snippet:
    Code :
    var texture = gl.createTexture();
    texture.image = new Image();
    texture.image.onload = function() { 
         .... // I want to read the pixels once the image has been loaded
    };
    texture.image.src = urlImage;
    I'd like to get the image pixels once it has been loaded.

    Is it possible? If so, what's the best to do it?

    Thanks in advance for your help.

  2. #2

    Re: Accessing image data

    I use HTML5 <canvas> to read the texels with the following code snippets:
    Code :
    var myCanvas = document.createElement("canvas");
    myCanvas.width = texture.image.width; 
    myCanvas.height = texture.image.height;
    var myCanvasContext = myCanvas.getContext("2d"); // Get canvas 2d context
    myCanvasContext.drawImage(texture.image, 0, 0); // Draw the texture
    var texels = myCanvasContext.getImageData(0,0, width, height); // Read the texels/pixels back
    It does what I want to do. Please let me know if there is a better way

Similar Threads

  1. accessing elements of cl::Buffer?
    By qwer in forum OpenCL
    Replies: 1
    Last Post: 01-31-2011, 11:24 AM
  2. Replies: 1
    Last Post: 12-08-2009, 06:26 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
  •