VintaSoft Imaging .NET SDK 12.3: Documentation for .NET developer
Vintasoft.Imaging Namespace / VintasoftImage Class / Save Methods / Save(Stream,EncoderBase) Method
Syntax Exceptions Remarks Example Requirements SeeAlso
In This Topic
    Save(Stream,EncoderBase) Method (VintasoftImage)
    In This Topic
    Saves this VintasoftImage object to the specified stream using specified encoder.
    Syntax

    Parameters

    stream
    Stream where the image should be saved.
    encoder
    Encoder to save the image.
    Exceptions
    ExceptionDescription
    Thrown if stream or encoder is null.
    Thrown if error occurs at saving the image.
    Remarks

    Supported image formats: BMP, GIF, JBIG2, JPEG, PCX, PDF, PNG, TIFF.

    Suitable encoder is selected automatically from the extension of the filename, exception is thrown if encoder is not found for file extension specified in filename.

    If image is saving to new file (stream != SourceInfo.Stream) this method:

    • saves image to new BMP/GIF/JBIG2/JPEG/PCX/PDF/PNG/TIFF file if MultipageEncoderBase.CreateNewFile = true; file specified by filename is replaced if it exists
    • saves image to new JBIG2/PDF/TIFF file if MultipageEncoderBase.CreateNewFile = false and file specified by filename is not exist
    • adds image to new JBIG2/PDF/TIFF file if MultipageEncoderBase.CreateNewFile = false and file specified by filename is exist

    If image is saving to the source file (stream == SourceInfo.Stream) this method:
    • saves image to the source BMP/GIF/JBIG2/JPEG/PCX/PDF/PNG/TIFF file if image is changed (IsChanged = true) and source file contains only one image
    • throws an exception if image is saved to the source BMP/GIF/JBIG2/JPEG/PCX/PDF/PNG/TIFF file and image is not changed (IsChanged = false)
    • adds image to the source JBIG2/PDF/TIFF file if MultipageEncoderBase.CreateNewFile = false, file specified by filename is exist

    Example

    This C#/VB.NET code shows how to load image from disk and save it to memory as JPEG stream.

    
    ' load image from file
    Using image As New Vintasoft.Imaging.VintasoftImage("c:\original-image.tif")
        Dim memory As New System.IO.MemoryStream()
        ' create JPEG encoder
        Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.JpegEncoder(New Vintasoft.Imaging.Codecs.Encoders.JpegEncoderSettings(10))
        ' save annotations with image
        encoder.AnnotationsFormat = Vintasoft.Imaging.AnnotationsFormat.VintasoftBinary
        ' save image to file
        image.Save(memory, encoder)
    End Using
    
    
    
    // load image from file
    using (Vintasoft.Imaging.VintasoftImage image =
        new Vintasoft.Imaging.VintasoftImage(@"c:\original-image.tif"))
    {
        System.IO.MemoryStream memory = new System.IO.MemoryStream();
        // create JPEG encoder
        Vintasoft.Imaging.Codecs.Encoders.JpegEncoder encoder =
            new Vintasoft.Imaging.Codecs.Encoders.JpegEncoder(
                new Vintasoft.Imaging.Codecs.Encoders.JpegEncoderSettings(10));
        // save annotations with image
        encoder.AnnotationsFormat = Vintasoft.Imaging.AnnotationsFormat.VintasoftBinary;
        // save image to file
        image.Save(memory, encoder);
    }
    
    

    Requirements

    Target Platforms: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also