Ejemplo n.º 1
0
        public void LoadRawTextureData(byte[] data)
        {
            Godot.Image image = new Godot.Image();
            Bitmap      bm;

            try
            {
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
                {
                    bm = new Bitmap(ms);
                }

                byte[] bytes   = new byte[bm.Width * bm.Height * 4];
                int    bytePos = 0;

                for (int y = 0; y < bm.Height; y++)
                {
                    for (int x = 0; x < bm.Width; x++)
                    {
                        var color = bm.GetPixel(x, y);
                        bytes[bytePos]     = color.R;
                        bytes[bytePos + 1] = color.G;
                        bytes[bytePos + 2] = color.B;
                        bytes[bytePos + 3] = color.A;
                        bytePos           += 4;
                    }
                }

                image.CreateFromData(bm.Width, bm.Height, false, Godot.Image.Format.Rgba8, bytes);
                _texture.CreateFromImage(image);
            }
            catch (System.Exception e)
            {
                Debug.Log(e.Message + "\n\n" + e.StackTrace);
            }
        }