当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.Texture2DToWriteableBitmap方法代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:Ninlay,项目名称:Terraria-Map-Editor,代码行数:50,代码来源:WorldRenderXna.xaml.cs


注:本文中的Microsoft.Xna.Framework.Graphics.Texture2D.Texture2DToWriteableBitmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。