Jump to content

How to get the screen buffer as an image


Recommended Posts

   Hi,  I am currently working on a project where I have a huge container, but I only want to capture what is in the screen buffer on the canvas.  I tried using getImageData, it didn't work since it is for 2d context not webgl. RenderTexture seems to scale the whole container down to the renderTexture size. Is there a way to get the screenbuffer on a 2d canvas so I can use as a texture ?  Thanks

Link to comment
Share on other sites

I changed your code to fit my version of PIXI.  It doesn't work for me. I get a blank image of the size of the huge container. It is blank maybe because the texture dimension is way too big. I need to get only what is shown on the screen like a screenshot. 

 var renderTexture = new PIXI.RenderTexture(renderer, renderer.width, renderer.height);


Link to comment
Share on other sites

It works.

Paste this to http://pixijs.github.io/examples/index.html?s=basics&f=tiling-sprite.js&title=Tiling+Sprite&v=v3.0.11 :


var renderer = PIXI.autoDetectRenderer(800, 600);

// create the root of the scene graph
var stage = new PIXI.Container();

// create a texture from an image path
var texture = PIXI.Texture.fromImage('_assets/p2.jpeg');

/* create a tiling sprite ...
 * requires a texture, a width and a height
 * in WebGL the image size should preferably be a power of two
var tilingSprite = new PIXI.extras.TilingSprite(texture, renderer.width, renderer.height);

var count = 0;


setTimeout(function() {
  var renderTexture = new PIXI.RenderTexture(renderer, renderer.width, renderer.height);
  var canvas = renderTexture.getCanvas();
}, 1000);

function animate() {

    count += 0.005;

    tilingSprite.tileScale.x = 2 + Math.sin(count);
    tilingSprite.tileScale.y = 2 + Math.cos(count);

    tilingSprite.tilePosition.x += 1;
    tilingSprite.tilePosition.y += 1;

    // render the root container



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...