public override Texture2D Load(string name, Stream stream) { var png = new APNG(); png.Load(stream); return(new Texture2D(Path.GetFileName(name), png[0].Width, png[0].Height)); }
public override APNGFrameList Import(string filename, ContentImporterContext context) { var apng = new APNG(filename); APNGFrameList frameList; if (apng.IsSimplePNG) { frameList = new APNGFrameList(0); frameList.AddFrame(new TimeSpan(), BuildTextureContent(apng.DefaultImage.GetStream().ToArray())); } else { frameList = new APNGFrameList(apng.acTLChunk.NumPlays); if (!apng.DefaultImageIsAnimeated) { frameList.AddFrame( new TimeSpan(TimeSpan.TicksPerSecond * apng.DefaultImage.fcTLChunk.DelayNum / apng.DefaultImage.fcTLChunk.DelayDen), BuildTextureContent(apng.DefaultImage.GetStream().ToArray())); } foreach (LibAPNG.Frame frame in apng.Frames) { frameList.AddFrame( new TimeSpan(TimeSpan.TicksPerSecond * frame.fcTLChunk.DelayNum / frame.fcTLChunk.DelayDen), BuildTextureContent(frame.GetStream().ToArray())); } } return(frameList); }
public Program(APNG png) : base(400, 300, GraphicsMode.Default, "APNG Demo") { APNGFile = png; CurrentFrameNumber = 0; Textures = new List <int>(); }
public APNGHelper(Game game, string pngFile) { this.game = game; var image = new APNG(pngFile); numPlays = (int)image.acTLChunk.NumPlays; baseFrame = new APNGFrame(game, image.DefaultImage); if (image.IsSimplePNG) { CurrentFrame = baseFrame.FrameTexture; } else { numPlays = (int)image.acTLChunk.NumPlays; foreach (Frame frame in image.Frames) { frameList.Add(new APNGFrame(this.game, frame)); } sb = new SpriteBatch(this.game.GraphicsDevice); RenderEachFrame(); CurrentFrame = renderedTextureList[0]; } }
private void AnimatedImageViewer_DragDrop(object sender, DragEventArgs e) { string filename = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; picApng.Image = APNG.FromFile(filename); this.Width = picApng.Image.ViewSize.Width; this.Height = picApng.Image.ViewSize.Height; }
private static void TestEncoder(UInt32 imageDimension, IEncoder enc) { var i = new Bitmap((int)imageDimension, (int)imageDimension, PixelFormat.Format24bppRgb); var g = Graphics.FromImage(i); g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, i.Width, i.Height); g.DrawEllipse(new Pen(Color.IndianRed), 1, 1, i.Width / 2, i.Height / 2); g.DrawRectangle(new Pen(Color.GreenYellow, 4), i.Width / 2, i.Width / 2, i.Width / 2 - 4, i.Width / 2 - 4); var ihdr = new Ihdr(imageDimension, imageDimension, BitDepth._8, ColorType.Rgb); var apng = new APNG(ihdr); apng.RegisterDecoder(new SimpleDecoder()); apng.Encoder = enc; apng.AddDefaultImageFromObject(i); var frames = new Frame[i.Height / 2]; for(int j = 0; j < i.Height / 2; j++) { var bmp = new Bitmap((int)imageDimension, (int)imageDimension, PixelFormat.Format24bppRgb); var gr = Graphics.FromImage(bmp); gr.Clear(Color.Blue); gr.DrawEllipse(new Pen(Color.Lime), bmp.Width / 4, j, bmp.Width / 2, bmp.Height / 2); frames[j] = new Frame() { Delay = new Rational(10, 100), FrameObject = bmp }; } apng.SetFrames(frames); String fileName = String.Format("{0}_{1}x{2}_{3}.png", enc.GetType().Name, imageDimension, imageDimension, 0); if(File.Exists(fileName)) File.Delete(fileName); apng.ToFile(fileName); ihdr = new Ihdr(imageDimension, imageDimension, BitDepth._8, ColorType.Rgb); apng = new APNG(ihdr); apng.RegisterDecoder(new SimpleDecoder()); apng.Encoder = enc; String nowString = DateTime.UtcNow.ToString(@"yyyy\-MM\-dd HH:mm"); g.Clear(Color.Blue); g.DrawString(nowString, new Font("Consolas", 7), new SolidBrush(Color.Lime), 5, i.Height / 2f); apng.AddDefaultImageFromObject(i); frames = new Frame[i.Height / 2-10]; for(int j = 10; j < i.Height / 2; j++) { var bmp = new Bitmap((int)imageDimension, (int)imageDimension, PixelFormat.Format24bppRgb); var gr = Graphics.FromImage(bmp); gr.Clear(Color.Blue); gr.DrawString(nowString, new Font("Consolas", 7), new SolidBrush(Color.Lime), 5, j); frames[j-10] = new Frame() { Delay = new Rational(10, 100), FrameObject = bmp }; } apng.SetFrames(frames); fileName = String.Format("{0}_{1}x{2}_{3}.png", enc.GetType().Name, imageDimension, imageDimension, 1); if(File.Exists(fileName)) File.Delete(fileName); apng.ToFile(fileName); }
public AnimatedImageViewer(string[] args) { InitializeComponent(); if (args != null && args.Length > 0) { picApng.Image = APNG.FromFile(args[args.Length - 1]); this.Width = picApng.Image.ViewSize.Width; this.Height = picApng.Image.ViewSize.Height; } }
void collectProc(object data) { ThreadCollectModel md = data as ThreadCollectModel; APNG apngBase = new APNG(); do { if (md.needStop) { return; } const int waitTime = 10; //Dictionary<int, PNG> mapData = new Dictionary<int, PNG>(); List <PNG> lstData = new List <PNG>(); lock (md.mapData) { for (int i = 0; i < md.frameCount; ++i) { int idx = md.nowFrameIdx + i; if (!md.mapData.ContainsKey(idx)) { break; } lstData.Add(md.mapData[idx]); md.mapData.Remove(idx); } } if (lstData.Count <= 0) { Thread.Sleep(waitTime); continue; } for (int i = 0; i < lstData.Count; ++i) { apngBase.Add(lstData[i], md.fps); updateProgress(); } md.nowFrameIdx += lstData.Count; if (md.nowFrameIdx >= md.frameCount) { apngBase.Save(md.savePath); updateProgressToEnd(); clearThread(); } } while(!md.needStop); }
private byte[] BypassAPNG(byte[] Data) { try { var Image = new APNG(Data); if (Image.IsSimplePNG) { return(Data); } var Width = (int)Image.DefaultImage.fcTLChunk.Width; var Height = (int)Image.DefaultImage.fcTLChunk.Height; var TmpData = Image.DefaultImage.GetStream().ToArray(); using (var OriStrm = new MemoryStream(TmpData)) using (Bitmap BaseImage = (Bitmap)Bitmap.FromStream(OriStrm)) using (Bitmap Bitmap = new Bitmap(Width, Height)) using (Graphics g = Graphics.FromImage(Bitmap)) { g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.DrawImageUnscaled(BaseImage, Point.Empty); BaseImage?.Dispose(); OriStrm?.Dispose(); var LastFrame = Image.Frames.Last(); var XOffset = (int)LastFrame.fcTLChunk.XOffset; var YOffset = (int)LastFrame.fcTLChunk.YOffset; TmpData = LastFrame.GetStream().ToArray(); using (var LastStrm = new MemoryStream(TmpData)) using (Bitmap LastImg = new Bitmap(LastStrm)) g.DrawImageUnscaled(LastImg, new Point(XOffset, YOffset)); g.Flush(); using (var Output = new MemoryStream()) { Bitmap.Save(Output, ImageFormat.Png); return(Output.ToArray()); } } } catch { return(Data); } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> public bool fun_載入並判斷是否APNG(String path) { try { //載入 APNGFile = new APNGLib.APNG(); using (Stream s = File.OpenRead(path)) { APNGFile.Load(s); } return(APNGFile.IsAnimated);//判斷是否為APNG動畫 } catch { } return(false); }
private void GenerateAPNG(string filename, IList <FileInfo> files) { APNG apng = APNGAssembler.AssembleAPNG(files, true); if (apng != null) { Stream pngStr = apng.ToStream(); pngStr.Position = 0; using (FileStream fs = File.Create(filename)) { SevenZipCompressor compressor = new SevenZipCompressor(); compressor.CompressStream(pngStr, fs); } pngStr.Close(); } }
public APNGBox(APNG png) { APNGFile = png; CurrentFrameNumber = 0; Images = new List <Bitmap>(); InitImages(); Image = Images[0]; Size = Image.Size; playthroughs = 0; if (APNGFile.IsAnimated) { timer = new Timer(); timer.Interval = APNGFile.GetFrame(0).Milliseconds; timer.Tick += new EventHandler(timer_Tick); } }
private static void Main(string[] args) { if (args.Length != 1) { Console.Write("Usage: APNG.Test.exe filename.png"); Console.ReadKey(); return; } var apng = new APNG(args[0]); if (!apng.DefaultImageIsAnimeated) File.WriteAllBytes("0.png", apng.DefaultImage.GetStream().ToArray()); foreach (Frame frame in apng.Frames) { File.WriteAllBytes( frame.fcTLChunk.SequenceNumber.ToString() + ".png", frame.GetStream().ToArray()); } }
public List <Image> GetFramesFromAnimatePNG(string img) { List <Image> imageList = new List <Image>(); APNG png = new APNG(img); if (!png.DefaultImageIsAnimated) { throw new Exception("It's just a PNG... not APNG!"); } var firstFrame = new Bitmap(png.Frames[0].GetStream()); int size = firstFrame.Width > firstFrame.Height ? firstFrame.Width : firstFrame.Height; Debug.WriteLine(png.Frames.Count()); for (int i = 0; i < png.Frames.Count(); i++) { imageList.Add(Transparent2Color(ResizeImage(new Bitmap(png.Frames[i].GetStream()), size, size), panel1.BackColor)); } return(imageList); }
private static void Main(string[] args) { if (args.Length != 1) { Console.Write("Usage: APNG.Test.exe filename.png"); Console.ReadKey(); return; } var apng = new APNG(args[0]); if (!apng.DefaultImageIsAnimeated) { File.WriteAllBytes("0.png", apng.DefaultImage.GetStream().ToArray()); } foreach (Frame frame in apng.Frames) { File.WriteAllBytes( frame.fcTLChunk.SequenceNumber.ToString() + ".png", frame.GetStream().ToArray()); } }
public GifToTexturePatternAnimation(string FileName, BFRESGroupNode TargetFTEXFolder, FTXP ftxp) { string TextureName = System.IO.Path.GetFileNameWithoutExtension(FileName); string ext = Utils.GetExtension(FileName); ImageKeyFrame[] Images = new ImageKeyFrame[0]; if (ext == ".gif") { Image gifImg = Image.FromFile(FileName); //Add all the images Images = GetImages(gifImg); } if (ext == ".png" || ext == ".apng") { APNG png = new APNG(); png.Load(FileName); for (int i = 0; i < png.NumEmbeddedPNG; i++) { Images[i] = new ImageKeyFrame() { Frame = i, Image = png.ToBitmap(i) }; } } TargetFTEXFolder.ImportTexture(Images, TextureName); //Now load the key data to the animation ftxp.TexPatternAnim = new ResU.TexPatternAnim(); ftxp.TexPatternAnim.Name = ftxp.Text; ftxp.TexPatternAnim.Path = ""; ftxp.TexPatternAnim.FrameCount = Images.Length; ftxp.TexPatternAnim.TextureRefs = new ResU.ResDict <ResU.TextureRef>(); foreach (ImageKeyFrame key in Images) { string name = $"{TextureName}{key.Frame}"; ftxp.TexPatternAnim.TextureRefs.Add($"{TextureName}{key.Frame}", new ResU.TextureRef() { Name = $"{name}", Texture = ((FTEX)TargetFTEXFolder.ResourceNodes[name]).texture, }); } var material = new ResU.TexPatternMatAnim(); material.Name = "NewMaterial"; material.PatternAnimInfos = new List <ResU.PatternAnimInfo>(); material.BaseDataList.Add(0); ResU.PatternAnimInfo info = new ResU.PatternAnimInfo(); info.CurveIndex = 0; info.SubBindIndex = -1; info.Name = "_a0"; material.PatternAnimInfos.Add(info); ftxp.TexPatternAnim.TexPatternMatAnims.Add(material); ResU.AnimCurve curve = new ResU.AnimCurve(); curve.AnimDataOffset = 0; curve.CurveType = ResU.AnimCurveType.StepInt; curve.Delta = 0; curve.EndFrame = Images.Length; curve.StartFrame = 0; curve.FrameType = ResU.AnimCurveFrameType.Byte; curve.Scale = 1; curve.Offset = 0; curve.Frames = new float[(int)curve.EndFrame]; for (int i = 0; i < curve.EndFrame; i++) { curve.Frames[i] = Images[i].Frame; } curve.Keys = new float[(int)curve.Frames.Length, 1]; for (int i = 0; i < (ushort)curve.Keys.Length; i++) { int index = ftxp.TexPatternAnim.TextureRefs.IndexOf($"{TextureName}{Images[i].Frame}"); curve.Keys[i, 0] = index; } material.Curves.Add(curve); ftxp.UpdateMaterialBinds(); }