Пример #1
0
        public static Texture2D FromStream(Stream stream)
        {
            if (stream.CanSeek && stream.Position == stream.Length)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            int    width, height, len;
            IntPtr pixels = FNA3D.ReadImageStream(
                stream,
                out width,
                out height,
                out len
                );

            Texture2D result = new Texture2D(
                width,
                height
                );

            result.SetDataPointerEXT(
                0,
                null,
                pixels,
                len
                );

            FNA3D.FNA3D_Image_Free(pixels);
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Loads image data from a given stream.
        /// </summary>
        /// <remarks>
        /// This is an extension of XNA 4 and is not compatible with XNA. It exists to help with dynamically reloading
        /// textures while games are running. Games can use this method to read a stream into memory and then call
        /// SetData on a texture with that data, rather than having to dispose the texture and recreate it entirely.
        /// </remarks>
        /// <param name="stream">The stream from which to read the image data.</param>
        /// <param name="width">Outputs the width of the image.</param>
        /// <param name="height">Outputs the height of the image.</param>
        /// <param name="pixels">Outputs the pixel data of the image, in non-premultiplied RGBA format.</param>
        /// <param name="requestedWidth">Preferred width of the resulting image data</param>
        /// <param name="requestedHeight">Preferred height of the resulting image data</param>
        /// <param name="zoom">false to maintain aspect ratio, true to crop image</param>
        public static void TextureDataFromStreamEXT(
            Stream stream,
            out int width,
            out int height,
            out byte[] pixels,
            int requestedWidth  = -1,
            int requestedHeight = -1,
            bool zoom           = false
            )
        {
            if (stream.CanSeek && stream.Position == stream.Length)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            int    len;
            IntPtr pixPtr = FNA3D.ReadImageStream(
                stream,
                out width,
                out height,
                out len,
                requestedWidth,
                requestedHeight,
                zoom
                );

            pixels = new byte[len];
            Marshal.Copy(pixPtr, pixels, 0, len);

            FNA3D.FNA3D_Image_Free(pixPtr);
        }
Пример #3
0
        public static Texture2D FromStream(
            GraphicsDevice graphicsDevice,
            Stream stream,
            int width,
            int height,
            bool zoom
            )
        {
            if (stream.CanSeek && stream.Position == stream.Length)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            int    realWidth, realHeight, len;
            IntPtr pixels = FNA3D.ReadImageStream(
                stream,
                out realWidth,
                out realHeight,
                out len,
                width,
                height,
                zoom
                );

            Texture2D result = new Texture2D(
                graphicsDevice,
                realWidth,
                realHeight
                );

            result.SetDataPointerEXT(
                0,
                null,
                pixels,
                len
                );

            FNA3D.FNA3D_Image_Free(pixels);
            return(result);
        }