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




stream
A Stream where the image data will be saved.
offset
The offset within the specified stream where the saved image file will be embedded. For example, if you specify 5, then 5 bytes of other data will precede the embedded file.
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 RasterImageViewerElement.Image into stream.
Saves an Image to a stream using an offset within it, in any of the supported compressed or uncompressed formats.

Syntax

Visual Basic (Declaration) 
Overloads Public Function Save( _
   ByVal stream As Stream, _
   ByVal offset As Long, _
   ByVal format As RasterImageFormat, _
   ByVal bitsPerPixel As Integer, _
   ByVal qualityFactor As Integer _
) As Long
Visual Basic (Usage)Copy Code
Dim instance As RasterImageViewerElement
Dim stream As Stream
Dim offset As Long
Dim format As RasterImageFormat
Dim bitsPerPixel As Integer
Dim qualityFactor As Integer
Dim value As Long
 
value = instance.Save(stream, offset, format, bitsPerPixel, qualityFactor)
C# 
public long Save( 
   Stream stream,
   long offset,
   RasterImageFormat format,
   int bitsPerPixel,
   int qualityFactor
)
Managed Extensions for C++ 
public: long Save( 
   Stream* stream,
   long offset,
   RasterImageFormat format,
   int bitsPerPixel,
   int qualityFactor
) 
C++/CLI 
public:
long Save( 
   Stream^ stream,
   long offset,
   RasterImageFormat format,
   int bitsPerPixel,
   int qualityFactor
) 

Parameters

stream
A Stream where the image data will be saved.
offset
The offset within the specified stream where the saved image file will be embedded. For example, if you specify 5, then 5 bytes of other data will precede the embedded file.
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 RasterImageViewerElement.Image into stream.

Return Value

The size of the embedded image file, in bytes.

Example

This example will save an image to a stream before loading it back.

Visual BasicCopy Code
Public Sub RasterImageViewerElement_Save3(ByVal viewer As RasterImageViewerElement)
   Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"
   Dim destFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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, 128)

   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 RasterImageViewerElement_Save3(RasterImageViewerElement viewer) 

   string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; 
   string destFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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, 128); 
 
   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

Leadtools.Windows.Controls.Pro.dxp requires a WFP Module license and unlock key. For more information, refer to: Raster Pro/Document/Medical Features and Unlocking Special LEAD Features.