コード例 #1
0
        protected virtual Texture2D LoadTextureFromStream(FileStream fileStream)
        {
            var texture = Texture2D.FromStream(this.graphicsDevice, fileStream);

            if (texture.Format != SurfaceFormat.Color)
            {
                return(texture);
            }

            // unfortunately, MonoGame loads textures as non-premultiplied alpha
            // need to premultiply alpha for correct rendering with NoesisGUI
            var buffer = new Color[texture.Width * texture.Height];

            texture.GetData(buffer);
            for (var i = 0; i < buffer.Length; i++)
            {
                buffer[i] = Color.FromNonPremultiplied(
                    buffer[i].R,
                    buffer[i].G,
                    buffer[i].B,
                    buffer[i].A);
            }

            texture.SetData(buffer);
            return(texture);
        }
コード例 #2
0
 public static XNACOLOR ToXnaPremul(this XNACOLOR c)
 {
     return(XNACOLOR.FromNonPremultiplied(c.R, c.G, c.B, c.A));
 }