0

I can take a "screenshot" from my form(backbufferdata), but is it possible to take only a part of it ? lets say, if my form is 1600x800 px, is it possible to get only 100x100 px ?

int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
int h = GraphicsDevice.PresentationParameters.BackBufferHeight;

//pull the picture from the buffer 
int[] backBuffer = new int[w * h];
GraphicsDevice.GetBackBufferData(backBuffer);

//copy into a texture 
Texture2D texture = new Texture2D(GraphicsDevice, w, h, true, GraphicsDevice.PresentationParameters.BackBufferFormat);
texture.SetData(backBuffer);

If i change the width en height it gives an error "it's too small or too big".

4

1 回答 1

1

尝试使用GraphicsDevice.GetBackBufferData 通用方法 (Nullable, T[], Int32, Int32)

例如:

int posX = 0; // area position
int posY = 0;
int w = 200;  // area size
int h = 100;

//pull the picture from the buffer 
int[] backBuffer = new int[w * h];
GraphicsDevice.GetBackBufferData(new Rectangle(posX, posY, w, h), backBuffer, 0, w*h );

//copy into a texture 
Texture2D texture = new Texture2D(GraphicsDevice, w, h, true, GraphicsDevice.PresentationParameters.BackBufferFormat);
texture.SetData(backBuffer);
于 2013-05-21T03:15:21.613 回答