Engines/FlatRedBallXNA/FlatRedBall/IO/PngLoader.cs
/// <summary>
/// Loads a .png image from the fileName given and returns an array of pixel colors.
/// </summary>
/// <param name="fileName">The name of the .png image to be loaded.</param>
/// <returns>
/// Returns a Microsoft.Xna.Framework.Graphics.Color[] containing one item(Color) for each pixel
/// in the image.</returns>
Loads a .png image from the fileName given and returns an array of pixel colors.
Loads a . png image from the fileName given and returns an array of pixel colors .
public static ImageData GetPixelData(string fileName)
        {
            for (int i = 0; i < ByteBufferSize; i++)
            {
                mTransparentEntries[i] = byte.MaxValue;
            }
            int bytesRead = LoadFile(fileName);
            mMaxTransIndex = -1;
            Stream sourceStream = new MemoryStream(sByteBuffer, 0, bytesRead);
            if (!CheckSignature(ref sourceStream))
                throw new ArgumentException(
                    String.Format("Argument Stream {0} does not contain a valid PNG file.", sourceStream));
            List<Chunk> chunks = new List<Chunk>();
            while (GetNextChunk(ref sourceStream, ref chunks)) { }
            sourceStream.Close();
            HeaderInfo header = ReadHeader(ref chunks);
            PaletteInfo palette = new PaletteInfo();
            byte[] filteredImage = ProcessChunks(chunks, header, ref palette);
            byte[] defilteredImage = ReverseFiltering(filteredImage, header);
            Color[] pixelData = BuildPixels(defilteredImage, ref header, ref palette);
            ImageData imageData = new ImageData((int)header.Width, (int)header.Height, pixelData);
            return imageData;
        }
public static ImageData GetPixelData ( string fileName ) { for ( int i = 0 ; i < ByteBufferSize ; i ++ ) { mTransparentEntries [ i ] = byte . MaxValue ; } int bytesRead = LoadFile ( fileName ) ; mMaxTransIndex = - 1 ; Stream sourceStream = new MemoryStream ( sByteBuffer , 0 , bytesRead ) ; if ( ! CheckSignature ( ref sourceStream ) ) throw new ArgumentException ( String . Format ( " " , sourceStream ) ) ; List < Chunk > chunks = new List < Chunk > ( ) ; while ( GetNextChunk ( ref sourceStream , ref chunks ) ) { } sourceStream . Close ( ) ; HeaderInfo header = ReadHeader ( ref chunks ) ; PaletteInfo palette = new PaletteInfo ( ) ; byte [ ] filteredImage = ProcessChunks ( chunks , header , ref palette ) ; byte [ ] defilteredImage = ReverseFiltering ( filteredImage , header ) ; Color [ ] pixelData = BuildPixels ( defilteredImage , ref header , ref palette ) ; ImageData imageData = new ImageData ( ( int ) header . Width , ( int ) header . Height , pixelData ) ; return imageData ; }
Loads a .png image from the fileName given and returns an array of pixel colors.
Loads a . png image from the fileName given and returns an array of pixel colors .
//Load the file into "byte stream" //Check the signature to verify this is an actual .png image //Since all data in .png files is organized into categorized chunks, create a //List to store them in so that they can be read and processed later. //Load each Chunk of data from the stream into the List of Chunks. Then //close the stream. //Read and store the information from the IHDR chunk, which contains //general info for this image. Note: IHDR chunk is removed from List<Chunk> chunks. //Create an empty palette in case we need it //Process the Chunks of data and obtain the decompressed bytes of the image //Reverse the filtering that was done on the image before compression //Translate the un-filtered image bytes into Colors and store in the array to be returned. //System.Diagnostics.Trace.WriteLine(pixelData.Length);
Returns a Microsoft.Xna.Framework.Graphics.Color[] containing one item(Color) for each pixel
in the image.
Returns a Microsoft . Xna . Framework . Graphics . Color [] containing one item ( Color ) for each pixel in the image .
fileName
string
The name of the .png image to be loaded.
The name of the . png image to be loaded .