AGS.Editor.SpriteSelector.LoadSpriteFileFromDisk C# (CSharp) Метод

LoadSpriteFileFromDisk() приватный Метод

private LoadSpriteFileFromDisk ( string fileName ) : Bitmap
fileName string
Результат System.Drawing.Bitmap
        private Bitmap LoadSpriteFileFromDisk(string fileName)
        {
            // We have to use this stream code because using "new Bitmap(filename)"
            // keeps the file open until the Bitmap is disposed
            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            Bitmap loadedBmp = (Bitmap)Bitmap.FromStream(fileStream);
            fileStream.Close();

            // Unfortunately the Bitmap.Clone method will crash later due to
            // a .NET bug when it's loaded from a stream. Therefore we need
            // to make a fresh copy.
            loadedBmp = Utilities.CreateCopyOfBitmapPreservingColourDepth(loadedBmp);

            //Bitmap loadedBmp = new Bitmap(fileName);
            if ((System.IO.Path.GetExtension(fileName).ToLower() == ".gif") &&
                (loadedBmp.PixelFormat != PixelFormat.Format8bppIndexed))
            {
                // The .NET Bitmap class has a bug, whereby it will convert
                // animated gifs to 32-bit when it loads them. This causes
                // us an issue, so use the custom GifDecoder instead when
                // this happens.
                loadedBmp.Dispose();

                GifDecoder decoder = new GifDecoder();
                if (decoder.Read(fileName) != GifDecoder.STATUS_OK)
                {
                    throw new AGS.Types.InvalidDataException("Unable to load GIF");
                }
                loadedBmp = decoder.GetFrame(0);
            }
            return loadedBmp;
        }