Leadtools.Windows.Controls.Pro Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Save(Stream,RasterImageFormat,Int32,Int32) Method
See Also  Example
Leadtools.Windows.Controls Namespace > RasterImageViewer Class > Save Method : Save(Stream,RasterImageFormat,Int32,Int32) Method



stream
A Stream where the image data will be saved.
format
The output file format. For valid values, refer to Summary of All Supported Image File Formats.
bitsPerPixel
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of All Supported Image File Formats. If bitsPerPixel is 0, the image will be stored using the closest bits per pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits per pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as a 24-bit image. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as a 4-bit image.
qualityFactor
A quality factor to be used when saving RasterImageViewer.Image into a stream.
stream
A Stream where the image data will be saved.
format
The output file format. For valid values, refer to Summary of All Supported Image File Formats.
bitsPerPixel
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of All Supported Image File Formats. If bitsPerPixel is 0, the image will be stored using the closest bits per pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits per pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as a 24-bit image. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as a 4-bit image.
qualityFactor
A quality factor to be used when saving RasterImageViewer.Image into a stream.
Saves a Image to a stream in any of the supported compressed or uncompressed formats.

Syntax

Visual Basic (Declaration) 
Overloads Public Sub Save( _
   ByVal stream As Stream, _
   ByVal format As RasterImageFormat, _
   ByVal bitsPerPixel As Integer, _
   ByVal qualityFactor As Integer _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterImageViewer
Dim stream As Stream
Dim format As RasterImageFormat
Dim bitsPerPixel As Integer
Dim qualityFactor As Integer
 
instance.Save(stream, format, bitsPerPixel, qualityFactor)
C# 
public void Save( 
   Stream stream,
   RasterImageFormat format,
   int bitsPerPixel,
   int qualityFactor
)
C++/CLI 
public:
void Save( 
   Stream^ stream,
   RasterImageFormat format,
   int bitsPerPixel,
   int qualityFactor
) 

Parameters

stream
A Stream where the image data will be saved.
format
The output file format. For valid values, refer to Summary of All Supported Image File Formats.
bitsPerPixel
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of All Supported Image File Formats. If bitsPerPixel is 0, the image will be stored using the closest bits per pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits per pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as a 24-bit image. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as a 4-bit image.
qualityFactor
A quality factor to be used when saving RasterImageViewer.Image into a stream.

Example

This example will load a 24 bits per pixel CMP image and save it to a stream.

Visual BasicCopy Code
Public Sub RasterImageViewer_Save1(ByVal viewer As RasterImageViewer)
    Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
    Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_SaveStream3.bin"

    ' Load the source image
    viewer.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1)

    ' Create a memory stream
    Dim ms As MemoryStream = New MemoryStream()

    ' Save this image to the stream after the header
    Console.WriteLine("Saving the image")
    Dim position As Long = viewer.Save(ms, 0, RasterImageFormat.Cmp, 24, 100)

    Console.WriteLine("{0} bytes saved to the stream")

    ' Save the stream to a file
    'INSTANT VB NOTE: The following 'using' block is replaced by its pre-VB.NET 2005 equivalent:
    ' using (FileStream fs = File.Create(destFileName))
    Dim fs As FileStream = File.Create(destFileName)
    Try
        ms.WriteTo(fs)
    Finally
        CType(fs, IDisposable).Dispose()
    End Try

    ms.Close()

    ' Make sure the saved file works

    ' Save the image to disk
    Console.WriteLine("Loading the file back")
    viewer.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1)
End Sub
C#Copy Code
public void RasterImageViewer_Save1(RasterImageViewer viewer) 

   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_SaveStream3.bin"; 
 
   // Load the source image 
   viewer.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1); 
 
   // Create a memory stream 
   MemoryStream ms = new MemoryStream(); 
 
   // Save this image to the stream after the header 
   Console.WriteLine("Saving the image"); 
   long position = viewer.Save(ms, 0, RasterImageFormat.Cmp, 24, 100); 
 
   Console.WriteLine("{0} bytes saved to the stream"); 
 
   // Save the stream to a file 
   using (FileStream fs = File.Create(destFileName)) 
      ms.WriteTo(fs); 
 
   ms.Close(); 
 
   // Make sure the saved file works 
 
   // Save the image to disk 
   Console.WriteLine("Loading the file back"); 
   viewer.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1); 
}

Remarks

You can set the qualityFactor parameter to a value from 2 to 255 when saving JPEG and LEAD CMP compressed images, where 2 represents the highest quality and 255 the most compression.

If the image is 8 bits per pixel or greater, use the LEAD CMP format or one of the JPEG (JTIF or JFIF) formats to save disk space.

If the image is 1 bit per pixel, use the LEAD 1-bit format or a CCITT Group 3 or 4 format to save disk space.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family

See Also