本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Texture2D.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.Save方法的具体用法?C# Texture2D.Save怎么用?C# Texture2D.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.Texture2D
的用法示例。
在下文中一共展示了Texture2D.Save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeScreenshot
/// <summary>
/// Make screenshot
/// </summary>
private void MakeScreenshot()
{
try
{
//NOTE: This doesn't always work on all cards, especially if
// desktop mode switches in fullscreen mode!
screenshotNum++;
// Make sure screenshots directory exists
if (Directory.Exists(Directories.ScreenshotsDirectory) == false)
Directory.CreateDirectory(Directories.ScreenshotsDirectory);
using (Texture2D dstTexture = new Texture2D(
BaseGame.Device,
BaseGame.Width, BaseGame.Height, 1,
ResourceUsage.ResolveTarget,
SurfaceFormat.Color,
ResourceManagementMode.Manual))
{
// Get data with help of the resolve method
BaseGame.Device.ResolveBackBuffer(dstTexture);
dstTexture.Save(
ScreenshotNameBuilder(screenshotNum),
ImageFileFormat.Jpg);
} // using
} // try
catch (Exception ex)
{
Log.Write("Failed to save Screenshot: " + ex.ToString());
} // catch (ex)
}
示例2: DumpPickingBuffer_DEBUG
public void DumpPickingBuffer_DEBUG(string path, ImageFileFormat format)
{
Texture2D tex = new Texture2D(base.ScreenMgr.GraphicsDevice, 800, 600);
Color[] clrs = new Color[800 * 600];
for (int i = 0; i < 800; i++)
for (int j = 0; j < 600; j++)
clrs[i * 600 + j] = myPickingTexture[i, j];
tex.SetData<Color>(clrs);
tex.Save(path, format);
}
示例3: DrawReflectionMap
private void DrawReflectionMap() {
Vector3 planeNormalDirection = new Vector3( 0, 1, 0 );
planeNormalDirection.Normalize();
Vector4 planeCoefficients = new Vector4( planeNormalDirection, -waterHeight );
Matrix camMatrix = camera.reflectionView * camera.projection;
Matrix invCamMatrix = Matrix.Invert( camMatrix );
invCamMatrix = Matrix.Transpose( invCamMatrix );
planeCoefficients = Vector4.Transform( planeCoefficients, invCamMatrix );
Plane reflectionClipPlane = new Plane( planeCoefficients );
graphics.GraphicsDevice.ClipPlanes[ 0 ].Plane = reflectionClipPlane;
graphics.GraphicsDevice.ClipPlanes[ 0 ].IsEnabled = true;
graphics.GraphicsDevice.SetRenderTarget( 0, reflectionRenderTarg );
graphics.GraphicsDevice.Clear( ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0 );
if( skybox != null )
skybox.Draw( camera.reflectionView, camera.projection );
if( heightmap != null )
heightmap.Draw( camera.reflectionView, camera.projection );
graphics.GraphicsDevice.SetRenderTarget( 0, null );
reflectionMap = reflectionRenderTarg.GetTexture();
graphics.GraphicsDevice.ClipPlanes[ 0 ].IsEnabled = false;
if( bSaveReflection ) {
reflectionMap.Save( "reflectionMap.jpg", ImageFileFormat.Jpg );
Editor.console.Add( "Reflection jpeg saved." );
bSaveReflection = false;
}
}
示例4: GenerateSpriteSheet
//.........这里部分代码省略.........
XnaColor baseColor = XnaColor.Black;
if (overrideTransColor == true)
{
baseColor = new XnaColor(this.BaseTextureColor.R,
this.BaseTextureColor.G, this.BaseTextureColor.B, 0);
}
uint[] destinationData = new uint[width * height];
for (int i = 0; i < destinationData.Length; i++)
{
destinationData[i] = baseColor.PackedValue;
}
Texture2D spriteSheet = new Texture2D(IceCream.Drawing.DrawingManager.GraphicsDevice,
width, height);
foreach (SpriteInfo sprite in this.Sprites)
{
Texture2D source = sprite.Texture2D;
int x = sprite.X;
int y = sprite.Y;
int w = source.Width;
int h = source.Height;
int b = safeBorderSize;
int sourceSize = sprite.Texture2D.Width;
int destSize = width;
// Copy the main sprite data to the output sheet.
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, w, h),
ref destinationData, destSize, new Point(x + b, y + b),
baseColor.PackedValue, overrideTransColor);
// Copy a border strip from each edge of the sprite, creating
// a padding area to avoid filtering problems if the
// sprite is scaled or rotated.
for (int i = 0; i < safeBorderSize; i++)
{
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, 1, h),
ref destinationData, destSize, new Point(x + i, y + b),
baseColor.PackedValue, overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, 0, 1, h),
ref destinationData, destSize,
new Point(x + w + i + b, y + b), baseColor.PackedValue, overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, w, 1),
ref destinationData, destSize,
new Point(x + b, y + i), baseColor.PackedValue, overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, h - 1, w, 1),
ref destinationData, destSize,
new Point(x + b, y + h + i + b), baseColor.PackedValue, overrideTransColor);
// Copy a single pixel from each corner of the sprite,
// filling in the corners of the padding area.
for (int j = 0; j < b; j++)
{
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, 1, 1),
ref destinationData, destSize, new Point(x + j, y + i), baseColor.PackedValue,
overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, 1, 1),
ref destinationData, destSize, new Point(x + i, y + j), baseColor.PackedValue,
overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, 0, 1, 1),
ref destinationData, destSize, new Point(x + w + b + i, y + j),
baseColor.PackedValue, overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, 0, 1, 1),
ref destinationData, destSize, new Point(x + w + b + j, y + i), baseColor.PackedValue,
overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, h - 1, 1, 1),
ref destinationData, destSize, new Point(x + i, y + h + b + j), baseColor.PackedValue,
overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, h - 1, 1, 1),
ref destinationData, destSize, new Point(x + j, y + h + b + i), baseColor.PackedValue,
overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, h - 1, 1, 1),
ref destinationData, destSize, new Point(x + w + b + i, y + h + b + j),
baseColor.PackedValue, overrideTransColor);
sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, h - 1, 1, 1),
ref destinationData, destSize, new Point(x + w + b + j, y + h + b + i),
baseColor.PackedValue, overrideTransColor);
}
}
sprite.Area = new Rectangle(x + safeBorderSize, y + safeBorderSize,
sprite.Texture2D.Width, sprite.Texture2D.Height);
}
if (checkBoxAlphaCorrection.Checked == true)
{
CorrectAlphaBorders(destinationData, width, height, 2);
}
spriteSheet.SetData<uint>(destinationData);
ImageFileFormat format = (ImageFileFormat)comboBoxFileFormat.SelectedIndex;
String outputFilename = Path.Combine(outputPath, sheetName + "." + format.ToString().ToLowerInvariant());
spriteSheet.Save(outputFilename, format);
ExportXML(Path.Combine(outputPath, sheetName + ".xml"));
}