private async void Handle_Clicked(object sender, EventArgs e) { using (var loader = new GifLoader(Navigation, "loading.gif") { BackgroundColor = Color.Transparent }) { await Task.Delay(7000); } }
public static AnimationChain FromGif(string fileName, string contentManagerName) { if (FileManager.IsRelative(fileName)) { fileName = FileManager.RelativeDirectory + fileName; } if (FlatRedBallServices.IsLoaded <AnimationChain>(fileName, contentManagerName)) { return(FlatRedBallServices.GetNonDisposable <AnimationChain>(fileName, contentManagerName).Clone()); } ImageDataList imageDataList = GifLoader.GetImageDataList(fileName); int numberOfFrames = imageDataList.Count; AnimationChain animationChain = new AnimationChain(numberOfFrames); for (int i = 0; i < numberOfFrames; i++) { // We assume GIFs are for 2D games that don't need mipmaps. Could change this later // if needed const bool generateMipmaps = false; Texture2D texture2D = imageDataList[i].ToTexture2D(generateMipmaps, FlatRedBallServices.GraphicsDevice); texture2D.Name = fileName + i.ToString(); if (i >= imageDataList.FrameTimes.Count) { const double defaultFrameTime = .1; animationChain.Add( new AnimationFrame( texture2D, (float)defaultFrameTime)); } else { animationChain.Add( new AnimationFrame( texture2D, (float)imageDataList.FrameTimes[i])); } FlatRedBallServices.AddDisposable(texture2D.Name, texture2D, contentManagerName); } // Don't dispose the anything because it's part of the // content manager. animationChain.ParentGifFileName = fileName; animationChain.Name = FileManager.RemovePath(fileName); return(animationChain); }
static void Main(string[] args) { var loader = new GifLoader(); loader.Start(); }
Texture2D LoadTexture2D(string assetName, string extension) { Texture2D loadedAsset = null; if (Renderer.Graphics == null) { throw new NullReferenceException("The Renderer's Graphics is null. Call FlatRedBallServices.Initialize before attempting to load any textures"); } switch (extension.ToLowerInvariant()) { case "bmp": { ImageData bmp = FlatRedBall.IO.BmpLoader.GetPixelData(assetName); bmp.Replace(FlatRedBallServices.GraphicsOptions.TextureLoadingColorKey, Color.Transparent); Texture2D texture = bmp.ToTexture2D(); //new Texture2D(FlatRedBallServices.GraphicsDevice, bmp.Width, bmp.Height, 0, TextureUsage.None, SurfaceFormat.Color); //texture.SetData<Color>(bmp.Data); texture.Name = assetName; loadedAsset = texture; break; } case "png": case "jpg": bool useFrbPngLoader = false; if (useFrbPngLoader) { #if MONOGAME throw new NotImplementedException(); #else ImageData png = FlatRedBall.IO.PngLoader.GetPixelData(assetName); Texture2D texture = png.ToTexture2D(); texture.Name = assetName; loadedAsset = texture; #endif } else { Texture2D texture = LoadTextureFromFile(assetName); texture.Name = assetName; loadedAsset = texture; } break; case "dds": case "dib": case "hdr": case "pfm": case "ppm": case "tga": { throw new NotImplementedException("The following texture format is not supported" + extension + ". We recommend using the .png format"); //break; } case "gif": { #if MONOGAME throw new NotImplementedException(); #else ImageDataList imageDataList = GifLoader.GetImageDataList(assetName); int numberOfFrames = imageDataList.Count; if (imageDataList.Count == 0) { throw new InvalidOperationException("The gif file " + assetName + " has no frames"); } else { Texture2D texture2D = imageDataList[0].ToTexture2D(); texture2D.Name = assetName; loadedAsset = texture2D; } break; #endif } //break; default: throw new ArgumentException("FlatRedBall does not support the " + extension + " file type passed for loading a Texture2D"); //break; } return(loadedAsset); }