public static void Save(this BitmapSource bitmapSource, IO.Stream stream, BitmapEncoder encoder) { encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(stream); stream.Flush(); }