Exemple #1
0
        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;
        }
Exemple #2
0
        private void ImportMultipleGIFFrames(string fileName)
        {
            try
            {
                GifDecoder decoder = new GifDecoder();
                if (decoder.Read(fileName) != GifDecoder.STATUS_OK)
                {
                    throw new AGS.Types.InvalidDataException("Unable to load GIF");
                }

                int frameCount = decoder.GetFrameCount();
                for (int i = 0; i < frameCount; i++)
                {
                    Bitmap bmp = decoder.GetFrame(i);
                    CreateSpriteForBitmap(bmp, true, false, false);
                }
                decoder.Dispose();

                RefreshSpriteDisplay();
            }
            catch (Exception ex)
            {
                Factory.GUIController.ShowMessage("There was an error importing the file. The error message was: '" + ex.Message + "'. Please try again", MessageBoxIcon.Warning);
            }
        }