本文整理汇总了C#中GraphicsDevice.GetBackBufferData方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice.GetBackBufferData方法的具体用法?C# GraphicsDevice.GetBackBufferData怎么用?C# GraphicsDevice.GetBackBufferData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicsDevice
的用法示例。
在下文中一共展示了GraphicsDevice.GetBackBufferData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TakeScreenShot
public static void TakeScreenShot(GraphicsDevice device, Keys theKey)
{
currentState = Keyboard.GetState();
if (currentState.IsKeyDown(theKey) && preState.IsKeyUp(theKey))
{
byte[] screenData;
screenData = new byte[device.PresentationParameters.BackBufferWidth * device.PresentationParameters.BackBufferHeight * 4];
device.GetBackBufferData<byte>(screenData);
Texture2D Screenshot = new Texture2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, false, device.PresentationParameters.BackBufferFormat);
Screenshot.SetData<byte>(screenData);
string name = "Screenshot_" + counter + ".jpeg";
while (File.Exists(name))
{
counter += 1;
name = "Screenshot_" + counter + ".jpeg";
}
Stream stream = new FileStream(name, FileMode.Create);
Screenshot.SaveAsJpeg(stream, Screenshot.Width, Screenshot.Height);
stream.Close();
Screenshot.Dispose();
}
preState = currentState;
}
示例2: Screenshot
public static void Screenshot(GraphicsDevice device)
{
byte[] screenData;
screenData = new byte[device.PresentationParameters.BackBufferWidth * device.PresentationParameters.BackBufferHeight * 4];
device.GetBackBufferData<byte>(screenData);
Texture2D t2d = new Texture2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, false, device.PresentationParameters.BackBufferFormat);
t2d.SetData<byte>(screenData);
int i = 0;
string name = "ScreenShot" + i.ToString() + ".png";
while (File.Exists(name))
{
i += 1;
name = "ScreenShot" + i.ToString() + ".png";
}
Stream st = new FileStream(name, FileMode.Create);
t2d.SaveAsPng(st, t2d.Width, t2d.Height);
st.Close();
t2d.Dispose();
}
示例3: Capture
/// <summary>
/// Stores the current contents of the back buffer as a .PNG file.
/// </summary>
/// <param name="inGraphicsDevice">GraphicsDevice to grab the back buffer data from.</param>
/// <param name="inFilename">String containing the name of the file to save.</param>
/// <returns>True if the file is saved successfully, otherwise false.</returns>
public static bool Capture(GraphicsDevice inGraphicsDevice,
String inFilename, ScreenCaptureType inCaptureExtension)
{
if (inCaptureExtension == ScreenCaptureType.UseJPEG) { inFilename = inFilename + ".jpg"; }
if (inCaptureExtension == ScreenCaptureType.UsePNG) { inFilename = inFilename + ".png"; }
// Store the current BackBuffer data in a new array of Color values. This
// will take what is currently on the BackBuffer; everything current being
// drawn to the screen.
Color[] colorData = new Color[inGraphicsDevice.Viewport.Width *
inGraphicsDevice.Viewport.Height];
inGraphicsDevice.GetBackBufferData<Color>(colorData);
// Next set the colors into a Texture, ready for saving.
Texture2D backBufferTexture = new Texture2D(inGraphicsDevice,
inGraphicsDevice.Viewport.Width,
inGraphicsDevice.Viewport.Height);
backBufferTexture.SetData<Color>(colorData, 0, colorData.Length);
// Create the file after checking whether it exists. This requires a means
// of altering the intended filename so that it cannot overwrite an existing
// screen-capture, for instance suffixing an incremental digit onto the file
// name, but this would have to be saved to avoid overwritten files when the
// game crashes and the count is lost.
if (!File.Exists(inFilename))
{
using (FileStream fileStream = File.Create(inFilename))
{
// The choice passed in as the 3rd parameter just exists for the sake
// of providing options. If one is clearly advantageous to the other
// I'll hard-code it to use that instead. But, for now, we allow the
// choice between JPEG and PNG. PNG files have transparency.
switch (inCaptureExtension)
{
case ScreenCaptureType.UseJPEG:
backBufferTexture.SaveAsJpeg(fileStream,
inGraphicsDevice.Viewport.Width,
inGraphicsDevice.Viewport.Height);
break;
case ScreenCaptureType.UsePNG:
backBufferTexture.SaveAsPng(fileStream,
inGraphicsDevice.Viewport.Width,
inGraphicsDevice.Viewport.Height);
break;
}
fileStream.Flush();
}
return true;
}
return false;
}
示例4: PostProcess
public void PostProcess(GraphicsDevice myDevice)
{
if (
ResolvedTexture.Width != myDevice.Viewport.Width ||
ResolvedTexture.Height != myDevice.Viewport.Height ||
ResolvedTexture.Format != myDevice.DisplayMode.Format
) {
LoadResolveTarget(myDevice);
}
myDevice.GetBackBufferData(data);
ResolvedTexture.SetData(data);
myDevice.Textures[0] = ResolvedTexture;
foreach (EffectPass pass in Effect.CurrentTechnique.Passes) {
pass.Apply();
myDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, verts, 0, 2);
}
HMEffectManager.ScreenTexture = ResolvedTexture;
}
示例5: CaptureJpeg
public static bool CaptureJpeg(GraphicsDevice inGraphicsDevice, String inFilename)
{
inFilename = inFilename + ".jpeg";
// Store the current BackBuffer data in a new array of Color values. This
// will take what is currently on the BackBuffer; everything current being
// drawn to the screen.
Color[] colorData = new Color[inGraphicsDevice.Viewport.Width *
inGraphicsDevice.Viewport.Height];
inGraphicsDevice.GetBackBufferData<Color>(colorData);
// Next set the colors into a Texture, ready for saving.
Texture2D backBufferTexture = new Texture2D(inGraphicsDevice,
inGraphicsDevice.Viewport.Width,
inGraphicsDevice.Viewport.Height);
backBufferTexture.SetData<Color>(colorData, 0, colorData.Length);
// Create the file after checking whether it exists. This requires a means
// of altering the intended filename so that it cannot overwrite an existing
// screen-capture, for instance suffixing an incremental digit onto the file
// name, but this would have to be saved to avoid overwritten files when the
// game crashes and the count is lost.
if (!File.Exists(inFilename))
{
using (FileStream fileStream = File.Create(inFilename))
{
backBufferTexture.SaveAsJpeg(fileStream,
inGraphicsDevice.Viewport.Width,
inGraphicsDevice.Viewport.Height);
fileStream.Flush();
}
return true;
}
return false;
}