Example #1
0
        private static byte[] LoadFile(string fileName)
        {
            // September 14, 2010:
            // I think we can just standardize the reading of the file by simply by using
            // the GetStreamForFile method instead of branching.

//#if !WINDOWS_PHONE
//            System.Diagnostics.Trace.Write(Path.Combine(Microsoft.Xna.Framework.Storage.StorageContainer.TitleLocation, fileName.Replace("/", "\\")));


//            FileStream file = File.OpenRead(Path.Combine(Microsoft.Xna.Framework.Storage.StorageContainer.TitleLocation, fileName.Replace("/", "\\")));
//            byte[] source = ReadFile(file);

//            return source;
//#else


            Stream stream = FileManager.GetStreamForFile(fileName);

            byte[] source = ReadFile(stream);
            FileManager.Close(stream);

            return(source);
//#endif
        }
Example #2
0
        /// <summary>
        /// ImageData takes a fileName (string) and loads the BMP from the file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>a new ImageData, containing the width, height, and data of the BMP that was loaded</returns>
        public static ImageData GetPixelData(string fileName)
        {
            //Load the file into "byte stream"
            Stream sourceStream = new MemoryStream(LoadFile(fileName));

            //Check the signature to verify this is an actual .bmp image
            if (!CheckSignature(ref sourceStream))
            {
                throw new ArgumentException(
                          String.Format("Argument Stream {0} does not contain a valid BMP file.", sourceStream));
            }

            BMPHeader bmpHeader = new BMPHeader();

            ParseBytes(ref sourceStream, ref bmpHeader);
            FileManager.Close(sourceStream);

            return(new ImageData((int)bmpHeader.Width, (int)bmpHeader.Height, bmpHeader.Pixels));
        }