Engines/FlatRedBallXNA/FlatRedBall/IO/PngLoader.cs
/// <summary>
/// Reads the data in the given Stream and stores it in a byte[] that is then trimmed and returned.
/// </summary>
/// <param name="stream">A read-enabled Stream that is reading from a .png file.</param>
/// <returns>A byte[] containing the file being read through Stream stream.</returns>
Reads the data in the given Stream and stores it in a byte[] that is then trimmed and returned.
Reads the data in the given Stream and stores it in a byte [] that is then trimmed and returned .
private static int ReadFile(Stream stream)
        {
            int read = 0;
            int chunk;
            while ((chunk = stream.Read(sByteBuffer, read, sByteBuffer.Length - read)) > 0)
            {
                read += chunk;
                if (read == sByteBuffer.Length)
                {
                    int nextByte = stream.ReadByte();
                    if (nextByte == -1)
                    {
                        return read;
                    }
                    byte[] newBuffer = new byte[sByteBuffer.Length * 2];
                    Array.Copy(sByteBuffer, newBuffer, sByteBuffer.Length);
                    newBuffer[read] = (byte)nextByte;
                    sByteBuffer = newBuffer;
                    read++;
                }
            }
            return read;
        }
private static int ReadFile ( Stream stream ) { int read = 0 ; int chunk ; while ( ( chunk = stream . Read ( sByteBuffer , read , sByteBuffer . Length - read ) ) > 0 ) { read += chunk ; if ( read == sByteBuffer . Length ) { int nextByte = stream . ReadByte ( ) ; if ( nextByte == - 1 ) { return read ; } byte [ ] newBuffer = new byte [ sByteBuffer . Length * 2 ] ; Array . Copy ( sByteBuffer , newBuffer , sByteBuffer . Length ) ; newBuffer [ read ] = ( byte ) nextByte ; sByteBuffer = newBuffer ; read ++ ; } } return read ; }
Reads the data in the given Stream and stores it in a byte[] that is then trimmed and returned.
Reads the data in the given Stream and stores it in a byte [] that is then trimmed and returned .
//While there's something to read, read into the buffer. //update # of bytes read //if the buffer is full //check if this is the end of the stream //if so, return //otherwise, expand the buffer and repeat the process. //When done, copy into an array of the proper size and return.
A byte[] containing the file being read through Stream stream.
A byte [] containing the file being read through Stream stream .
stream
Stream
A read-enabled Stream that is reading from a .png file.
A read - enabled Stream that is reading from a . png file .