Leadtools.Windows.Controls.Pro Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.03.25
Save Method
See Also  Example
Leadtools.Windows.Controls Namespace > RasterImageViewer Class : Save Method




Saves a Image to a stream in any of the supported compressed or uncompressed formats.

Overload List

OverloadDescription
Save(Stream,RasterImageFormat,Int32,Int32) Saves a Image to a stream in any of the supported compressed or uncompressed formats.  
Save(String,RasterImageFormat,Int32,Int32) Saves a Image to a file in any of the supported compressed or uncompressed formats.  
Save(Stream,Int64,RasterImageFormat,Int32,Int32) Saves a Image to a stream using an offset within it, in any of the supported compressed or uncompressed formats.  

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 = "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, 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 = @"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, 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

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.