[API Proposal]: BitmapEncoder.Save(string path) override
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Background and motivation
`BitmapEncoder.Save` only takes a `Stream`. This is a proposal to add an override that takes a file path, similar to how there is `XmlDocument.Save(Stream)` and `XmlDocument.Save(string)`.
(The `BitmapDecoder` supports `Stream` and `Uri` sources.)
### API Proposal
```diff
namespace System.Windows.Media.Imaging
{
public abstract partial class BitmapEncoder : DispatcherObject
{
protected BitmapEncoder() { }
public virtual BitmapCodecInfo CodecInfo { get; }
public virtual ReadOnlyCollection ColorContexts { get; set; }
public virtual IList Frames { get; set; }
public virtual BitmapMetadata Metadata { get; set; }
public virtual BitmapPalette Palette { get; set; }
public virtual BitmapSource Preview { get; set; }
public virtual BitmapSource Thumbnail { get; set; }
public static BitmapEncoder Create(System.Guid containerFormat);
public virtual void Save(Stream stream);
+ public void Save(string filename);
}
}
```
### API Usage
```csharp
PngBitmapEncoder png = new();
png.Frames.Add(image);
png.Save("image.png");
```
instead of the currently required
```csharp
PngBitmapEncoder png = new();
png.Frames.Add(image);
using (FileStream stream = File.Create("image.png"))
{
png.Save(stream);
}
```
### Alternative Designs
_No response_
### Risks
Low, no behavior changed, minimum size requirements.
Contributor guide
Assessment
This issue has not been assessed yet.