ImageSave Method (Stream, ImageOptionsBase) |
Saves the image's data to the specified stream in the specified file format according to save options.
Namespace: Aspose.ImagingAssembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 22.05
Syntaxpublic void Save(
Stream stream,
ImageOptionsBase optionsBase
)
Public Sub Save (
stream As Stream,
optionsBase As ImageOptionsBase
)
public:
void Save(
Stream^ stream,
ImageOptionsBase^ optionsBase
)
member Save :
stream : Stream *
optionsBase : ImageOptionsBase -> unit
Parameters
- stream
- Type: System.IOStream
The stream to save the image's data to. - optionsBase
- Type: Aspose.ImagingImageOptionsBase
The save options.
Exceptions
ExamplesThe following example loads an image from a file, then saves the image to a PNG file stream.
[C#]
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
using (System.IO.Stream outputStream = System.IO.File.Open(dir + "output.png", System.IO.FileMode.Create))
{
image.Save(outputStream, saveOptions);
}
}
ExamplesThis example shows the process of Saving an Image to MemoryStream. To demonstrate this operation, example loads an existing file from some disk location, performs Rotate operation on the image and Save the image in PSD format
[C#]
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"C:\temp\sample.bmp"))
{
image.RotateFlip(Aspose.Imaging.RotateFlipType.Rotate180FlipX);
image.Save(stream, new Aspose.Imaging.ImageOptions.PsdOptions());
}
}
ExamplesThe following example shows how to save an entiree BMP image or part of it to a file or stream.
[C#]
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
bmpImage.BinarizeOtsu();
image.Save();
Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome();
saveOptions.BitsPerPixel = 1;
image.Save(dir + "sample.bw.palettized.bmp", saveOptions);
Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
image.Save(stream, saveOptions);
System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length);
}
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
image.Save(stream, saveOptions, bounds);
System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length);
}
}
See Also