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


C# RenderTarget2D.GetColorData方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.RenderTarget2D.GetColorData方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTarget2D.GetColorData方法的具体用法?C# RenderTarget2D.GetColorData怎么用?C# RenderTarget2D.GetColorData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Graphics.RenderTarget2D的用法示例。


在下文中一共展示了RenderTarget2D.GetColorData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromText

        public static Texture2D FromText(string text, SpriteFont font, Color color, Size size, bool multiLine, int lineStart, GraphicsDevice device)
        {
            string[] drawAbleText = multiLine ? text.Split(new string[1] { "\n" }, StringSplitOptions.None) : new string[1] { text };
            RenderTarget2D target = new RenderTarget2D(device, size.Width, size.Height);
            SpriteBatch sb = new SpriteBatch(device);

            device.SetRenderTarget(target);
            device.Clear(Color.Transparent);

            sb.Begin();
            for (int i = lineStart; i < drawAbleText.Length; i++)
            {
                float y = 1 + (i - lineStart) * font.GetHeight();
                sb.DrawString(font, drawAbleText[i], new Vector2(1, y), color, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            }
            sb.End();

            device.SetRenderTarget(null);

            Texture2D texture = new Texture2D(device, size.Width, size.Height);
            Color[] colorData = target.GetColorData();
            texture.SetData(colorData);

            target.Dispose();
            sb.Dispose();

            return texture;
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:28,代码来源:Drawing.cs

示例2: Refresh

        public override void Refresh()
        {
            base.Refresh();

            using (RenderTarget2D target = new RenderTarget2D(device, Bounds.Width, Bounds.Height))
            {
                SpriteBatch sb = new SpriteBatch(device);

                device.SetRenderTarget(target);
                device.Clear(Color.Transparent);

                sb.Begin();
                Draw(sb);
                sb.End();

                device.SetRenderTarget(null);
                image = ToDColorBmp(target.GetColorData(), Bounds.Width, Bounds.Height);
            }
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:19,代码来源:ImagedGuiItem.cs

示例3: FromLabels

        public static Texture2D FromLabels(KeyValuePair<string, Color>[] labels, SpriteFont font, Size size, GraphicsDevice device)
        {
            RenderTarget2D target = new RenderTarget2D(device, size.Width, size.Height);
            SpriteBatch sb = new SpriteBatch(device);

            device.SetRenderTarget(target);
            device.Clear(Color.Transparent);

            sb.Begin();
            for (int i = 0; i < labels.Length; i++)
            {
                string prevString = string.Join(" ", labels.Select(l => l.Key).ToArray(), 0, i);
                if (i > 0) prevString += " ";
                float x = 1 + font.MeasureString(prevString).X;

                sb.DrawString(font, labels[i].Key, new Vector2(x, 1), labels[i].Value, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            }
            sb.End();

            device.SetRenderTarget(null);

            Texture2D texture = new Texture2D(device, size.Width, size.Height);
            Color[] colorData = target.GetColorData();
            texture.SetData(colorData);

            target.Dispose();

            return texture;
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:29,代码来源:Drawing.cs

示例4: Stretch

        public static Texture2D Stretch(this Texture2D texture, Size size)
        {
            RenderTarget2D target = new RenderTarget2D(texture.GraphicsDevice, size.Width, size.Height);
            SpriteBatch sb = new SpriteBatch(texture.GraphicsDevice);

            texture.GraphicsDevice.SetRenderTarget(target);
            texture.GraphicsDevice.Clear(Color.Transparent);
            sb.Begin();
            sb.Draw(texture, new Rectangle(0, 0, size.Width, size.Height), Color.White);
            sb.End();

            texture.GraphicsDevice.SetRenderTarget(null);
            Texture2D result = new Texture2D(texture.GraphicsDevice, size.Width, size.Height);
            result.SetData(target.GetColorData());

            target.Dispose();
            sb.Dispose();

            return result;
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:20,代码来源:Extentions.cs

示例5: RenderOnto

        public static Texture2D RenderOnto(this Texture2D texture, Size size, Vector2 position = default(Vector2), float rotation = 0, Vector2 scale = default(Vector2))
        {
            RenderTarget2D target = new RenderTarget2D(texture.GraphicsDevice, size.Width, size.Height);
            SpriteBatch sb = new SpriteBatch(texture.GraphicsDevice);

            texture.GraphicsDevice.SetRenderTarget(target);
            texture.GraphicsDevice.Clear(Color.Transparent);
            sb.Begin();
            sb.Draw(texture, position, null, Color.White, rotation, Vector2.Zero, scale == default(Vector2) ? Vector2.One : scale, SpriteEffects.None, 1f);
            sb.End();

            texture.GraphicsDevice.SetRenderTarget(null);
            Texture2D result = new Texture2D(texture.GraphicsDevice, size.Width, size.Height);
            result.SetData(target.GetColorData());

            target.Dispose();
            sb.Dispose();


            return result;
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:21,代码来源:Extentions.cs


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