/// <summary> /// Gets image as bitmap source. /// </summary> /// <param name="frameIndex">Frame index.</param> /// <returns>WPF bitmap source.</returns> public BitmapSource GetImageAsBitmapSource(int frameIndex = 0) { if (frameIndex < 0 && frameIndex > Frames.Count) { return(null); } UltimaAnimationFrame frame = Frames[frameIndex]; return(BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgra32, null, frame.PixelData, frame.Width * 4)); }
/// <summary> /// Gets image as bitmap. /// </summary> /// <param name="frameIndex">Frame index.</param> /// <returns>Bitmap.</returns> public Bitmap GetImageAsBitmap(int frameIndex = 0) { if (frameIndex < 0 && frameIndex > Frames.Count) { return(null); } UltimaAnimationFrame frame = Frames[frameIndex]; Bitmap bitmap = new Bitmap(frame.Width, frame.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); BitmapData data = bitmap.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); Marshal.Copy(frame.PixelData, 0, data.Scan0, frame.PixelData.Length); bitmap.UnlockBits(data); return(bitmap); }