本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Texture2D.Texture2DToWriteableBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.Texture2DToWriteableBitmap方法的具体用法?C# Texture2D.Texture2DToWriteableBitmap怎么用?C# Texture2D.Texture2DToWriteableBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.Texture2D
的用法示例。
在下文中一共展示了Texture2D.Texture2DToWriteableBitmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTerrariaTextures
private void LoadTerrariaTextures(GraphicsDeviceEventArgs e)
{
// If the texture dictionary is valid (Found terraria and loaded content) load texture data
foreach (var id in World.NpcIds)
{
_textureDictionary.GetNPC(id.Value);
}
//foreach (var tile in World.TileProperties.Where(t => t.IsFramed))
//{
// var tileTexture = _textureDictionary.GetTile(tile.Id);
//}
foreach (var sprite in World.Sprites)
{
if (sprite.Size.X == 0 || sprite.Size.Y == 0)
continue;
try
{
var tile = World.TileProperties[sprite.Tile];
if (tile.TextureGrid.X == 0 || tile.TextureGrid.Y == 0)
continue;
var texture = new Texture2D(e.GraphicsDevice, sprite.Size.X * tile.TextureGrid.X, sprite.Size.Y * tile.TextureGrid.Y);
var tileTex = _textureDictionary.GetTile(sprite.Tile);
for (int x = 0; x < sprite.Size.X; x++)
{
for (int y = 0; y < sprite.Size.Y; y++)
{
var source = new Rectangle(x * (tile.TextureGrid.X + 2) + sprite.Origin.X, y * (tile.TextureGrid.Y + 2) + sprite.Origin.Y, tile.TextureGrid.X, tile.TextureGrid.Y);
if (source.Bottom > tileTex.Height)
source.Height -= (source.Bottom - tileTex.Height);
if (source.Right > tileTex.Width)
source.Width -= (source.Right - tileTex.Width);
var color = new Color[source.Height * source.Width];
var dest = new Rectangle(x * tile.TextureGrid.X, y * tile.TextureGrid.Y, source.Width, source.Height);
tileTex.GetData(0, source, color, 0, color.Length);
texture.SetData(0, dest, color, 0, color.Length);
}
}
sprite.IsPreviewTexture = true;
sprite.Preview = texture.Texture2DToWriteableBitmap();
}
catch (Exception ex)
{
ErrorLogging.LogException(ex);
}
}
}