本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.RenderTarget2D.SaveAsJpeg方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTarget2D.SaveAsJpeg方法的具体用法?C# RenderTarget2D.SaveAsJpeg怎么用?C# RenderTarget2D.SaveAsJpeg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.RenderTarget2D
的用法示例。
在下文中一共展示了RenderTarget2D.SaveAsJpeg方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
#region Set up screenshots
if (isScreenshot)
{
Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth *
GraphicsDevice.PresentationParameters.BackBufferHeight];
screenShot = new RenderTarget2D(GraphicsDevice,
GraphicsDevice.PresentationParameters.BackBufferWidth,
GraphicsDevice.PresentationParameters.BackBufferHeight);
GraphicsDevice.SetRenderTarget(screenShot);
map.Draw(spriteBatch);
base.Draw(gameTime);
GraphicsDevice.SetRenderTarget(null);
//save to disk
string fileName = DateTime.Now.ToString();
fileName = fileName.Replace('/', '-');
fileName = fileName.Replace(':', '-');
Stream stream = File.OpenWrite("\\Screens\\" + fileName + ".jpg");
screenShot.SaveAsJpeg(stream,
1280,
720);
stream.Dispose();
screenShot.Dispose();
//reset the screenshot flag
isScreenshot = false;
}
#endregion
map.Draw(spriteBatch);
base.Draw(gameTime);
}
示例2: SaveScreenshot
public void SaveScreenshot(string filename)
{
Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth * GraphicsDevice.PresentationParameters.BackBufferHeight];
RenderTarget2D screenShot = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
GraphicsDevice.SetRenderTarget(screenShot);
Draw(new GameTime());
GraphicsDevice.SetRenderTarget(null);
int index = 0;
string name = string.Concat(filename, "_", index, ".jpg");
while (File.Exists(name)) {
index++;
name = string.Concat(filename, "_", index, ".jpg");
}
using (FileStream stream = new FileStream(name, FileMode.CreateNew)) {
screenShot.SaveAsJpeg(stream, screenShot.Width, screenShot.Height);
screenShot.Dispose();
}
}
示例3: SaveData
/// <summary>
/// Saves all the undoRedoRenderTargets to disk and the imageStateData
/// </summary>
/// <param name='imageStateData'>Image state data.</param>
/// <param name='masterImageRenderTarget' Master image render target/>
/// <param name='undoRedoRenderTargets'>Sequence of images representing the undo/redo chain</param>
/// <param name='bottomMarginToCutOff'>Because the toolbox will always take up some space we will cut off the bottom section (toolbox height)
/// when saving the master image so that there is no annoying white space at the bottom</param>
public void SaveData(ImageStateData imageStateData, RenderTarget2D masterImageRenderTarget, RenderTarget2D[] undoRedoRenderTargets, int bottomMarginToCutOff)
{
this.SaveImageStateData(this.filenameResolver.MasterImageInfoFilename, imageStateData);
int end = imageStateData.FirstSavePoint == 0 ? imageStateData.LastSavePoint : imageStateData.MaxUndoRedoCount - 1;
for (int count = 0; count <= end; count++)
{
var renderTarget = undoRedoRenderTargets[count];
// Save the render target to disk
renderTarget.SaveAsPng(
this.filenameResolver.ImageSavePointFilename(count),
renderTarget.Width,
renderTarget.Height);
// copy the working canvas recorder file into the master folder.
var masterCanvasRecorderFile = this.filenameResolver.MasterCanvasRecorderFilename(count);
if (File.Exists(masterCanvasRecorderFile))
{
File.Delete(masterCanvasRecorderFile);
}
File.Move(this.filenameResolver.WorkingCanvasRecorderFilename(count), masterCanvasRecorderFile);
}
// Save the Master image as a JPG as it has no alpha channel - which is ideal for displaying on the home
// home screen where we don't want the background image showing through
masterImageRenderTarget.SaveAsJpeg(
this.filenameResolver.MasterImageFilename,
masterImageRenderTarget.Width,
masterImageRenderTarget.Height - bottomMarginToCutOff);
File.Delete(this.filenameResolver.WorkingImageInfoFilename);
}