Esempio n. 1
0
 private Texture BuildTexture(byte[] imageData, SlimDX.Direct3D9.Format imageFormat, int width, int height)
 {
     if (imageFormat == SlimDX.Direct3D9.Format.R8G8B8)
     {
         MemoryStream memoryStream;
         using (memoryStream = new MemoryStream())
         {
             Tex.makeRGB8(imageData, width, height).Save((Stream)memoryStream, ImageFormat.Bmp);
             memoryStream.Write(imageData, 0, imageData.Length);
             memoryStream.Position = 0L;
             return(Texture.FromStream(_Device, (Stream)memoryStream, width, height, 0, Usage.SoftwareProcessing, SlimDX.Direct3D9.Format.A8B8G8R8, Pool.Default, Filter.None, Filter.None, 0));
         }
     }
     else if (imageFormat == SlimDX.Direct3D9.Format.A8R8G8B8)
     {
         MemoryStream memoryStream;
         using (memoryStream = new MemoryStream())
         {
             Tex.makeRGB(imageData, width, height).Save((Stream)memoryStream, ImageFormat.Bmp);
             memoryStream.Write(imageData, 0, imageData.Length);
             memoryStream.Position = 0L;
             return(Texture.FromStream(_Device, (Stream)memoryStream, width, height, 0, Usage.SoftwareProcessing, SlimDX.Direct3D9.Format.A8B8G8R8, Pool.Default, Filter.None, Filter.None, 0));
         }
     }
     else
     {
         Texture texture = new Texture(_Device, width, height, 0, Usage.None, imageFormat, Pool.Managed);
         using (Stream data = (Stream)texture.LockRectangle(0, LockFlags.None).Data)
         {
             data.Write(imageData, 0, ((IEnumerable <byte>)imageData).Count <byte>());
             texture.UnlockRectangle(0);
         }
         return(texture);
     }
 }
Esempio n. 2
0
        private Texture BuildTexture(byte[] imageData, Format imageFormat, int width, int height)
        {
            Texture texture = null;

            if (imageFormat == Format.R8G8B8)
            {
                MemoryStream memoryStream2;
                MemoryStream memoryStream = memoryStream2 = new MemoryStream();
                try
                {
                    Tex.makeRGB8(imageData, width, height).Save(memoryStream, ImageFormat.Bmp);
                    memoryStream.Write(imageData, 0, imageData.Length);
                    memoryStream.Position = 0L;
                    Texture result = Texture.FromStream(this.device, memoryStream, width, height, 0, Usage.SoftwareProcessing, Format.A8B8G8R8, Pool.Default, Filter.None, Filter.None, 0);
                    return(result);
                }
                finally
                {
                    if (memoryStream2 != null)
                    {
                        ((IDisposable)memoryStream2).Dispose();
                    }
                }
            }
            if (imageFormat == Format.A8R8G8B8)
            {
                MemoryStream memoryStream3;
                MemoryStream memoryStream = memoryStream3 = new MemoryStream();
                try
                {
                    Tex.makeRGB(imageData, width, height).Save(memoryStream, ImageFormat.Bmp);
                    memoryStream.Write(imageData, 0, imageData.Length);
                    memoryStream.Position = 0L;
                    Texture result = Texture.FromStream(this.device, memoryStream, width, height, 0, Usage.SoftwareProcessing, Format.A8B8G8R8, Pool.Default, Filter.None, Filter.None, 0);
                    return(result);
                }
                finally
                {
                    if (memoryStream3 != null)
                    {
                        ((IDisposable)memoryStream3).Dispose();
                    }
                }
            }
            texture = new Texture(this.device, width, height, 0, Usage.None, imageFormat, Pool.Managed);
            using (Stream data = texture.LockRectangle(0, LockFlags.None).Data)
            {
                data.Write(imageData, 0, imageData.Count <byte>());
                texture.UnlockRectangle(0);
            }
            return(texture);
        }