BitmapEncoder.Save(Stream) Method

Definition

Encodes a bitmap image to a specified Stream.

C#
[System.Security.SecurityCritical]
public virtual void Save(System.IO.Stream stream);
C#
public virtual void Save(System.IO.Stream stream);

Parameters

stream
Stream

Identifies the file stream that this bitmap is encoded to.

Attributes

Exceptions

The bitmap has already been encoded.

The Frames count is less than or equal to zero.

Examples

The following example demonstrates how to save a bitmap image to a file stream by using the derived TiffBitmapEncoder class.

C#
FileStream stream = new FileStream("empty.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
encoder.Frames.Add(BitmapFrame.Create(image));
MessageBox.Show(myPalette.Colors.Count.ToString());
encoder.Save(stream);

Remarks

In the context of this API, "save" and "encode" are synonymous.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also