Whenever I try to call the getdata function, I keep getting an error "The size of the data passed in is too large or too small for this resource." I posted a quick test i did.
What am I doing wrong?
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace WindowsGameTest
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
int width = 400;
int height = 300;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.graphics.PreferredBackBufferWidth = width;
this.graphics.PreferredBackBufferHeight = height;
}
protected override void Initialize() { base.Initialize(); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); }
protected override void UnloadContent() { }
protected override void Update(GameTime gameTime) { base.Update(gameTime); }
protected override void Draw(GameTime gameTime)
{
ResolveTexture2D screenshot = new ResolveTexture2D(graphics.GraphicsDevice, width, height, 1, SurfaceFormat.Color);
graphics.GraphicsDevice.ResolveBackBuffer(screenshot);
byte[] image = new byte[screenshot.Width * screenshot.Height];
screenshot.GetData<byte>(image);
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
/*
SqlCommand command;
command = new SqlCommand("INSERT INTO Videos (timestamp,cameraID, image) VALUES (GETDATE(),4, @image)", conn);
//command.Parameters.Add("@datetime", SqlDbType.DateTime).Value = DateTime.Now;
command.Parameters.Add("@image", SqlDbType.Image).Value = image;
try
{
int i = command.ExecuteNonQuery();
}
catch
{
int i = 0;
}
*/
}
}
}