Leadtools.Codecs Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.17
Save(RasterImage,Stream,Int64,RasterImageFormat,Int32) Method
See Also  Example
Leadtools.Codecs Namespace > RasterCodecs Class > Save Method : Save(RasterImage,Stream,Int64,RasterImageFormat,Int32) Method




image
The RasterImage object that holds the image data.
stream
A Stream where the image data will be saved.
offset
The offset within the specified stream to embed the saved image file. 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, 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 closet bits/pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits/pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as 4 bit.
Saves the specified image to a stream using an offset within to begin saving.

Syntax

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

Parameters

image
The RasterImage object that holds the image data.
stream
A Stream where the image data will be saved.
offset
The offset within the specified stream to embed the saved image file. 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, 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 closet bits/pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits/pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as 4 bit.

Return Value

The size of the embedded image file in bytes.

Example

Visual BasicCopy Code
RasterCodecs.Save(RasterImage, Stream, long, RasterImageFormat, int)
      Public Sub SaveStream3Example()
         RasterCodecs.Startup()
         Dim codecs As RasterCodecs = New RasterCodecs()

         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
         Dim image As RasterImage = codecs.Load(srcFileName)

         ' 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 = codecs.Save(image, ms, 0, RasterImageFormat.Cmp, 24)
         image.Dispose()

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

         ' Save the stream to a file
         Using fs As FileStream = File.Create(destFileName)
            ms.WriteTo(fs)
         End Using

         ms.Close()

         ' Make sure the saved file works

         ' Save the image into disk
         Console.WriteLine("Loading the file back")
         image = codecs.Load(destFileName)
         image.Dispose()

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub
C#Copy Code
RasterCodecs.Save(RasterImage, Stream, long, RasterImageFormat, int) 
      public void SaveStream3Example() 
      { 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
 
         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 
         RasterImage image = codecs.Load(srcFileName); 
 
         // Create a memory stream 
         MemoryStream ms = new MemoryStream(); 
 
         // Save this image to the stream after the header 
         Console.WriteLine("Saving the image"); 
         long position = codecs.Save(image, ms, 0, RasterImageFormat.Cmp, 24); 
         image.Dispose(); 
 
         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 into disk 
         Console.WriteLine("Loading the file back"); 
         image = codecs.Load(destFileName); 
         image.Dispose(); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      }

Remarks

You can use this method to embed an image file in another file.

If the output file format supports multipage and then all the pages in image will be saved to the file.

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.

If the image has a region, the region stored in the image will be saved, if the image is saved as one of the TIFF file formats. Note, however, that the ability to save a region inside a TIFF file must be unlocked. This requires the Document Imaging Toolkit, Document Imaging Suite, Medical Imaging Toolkit, or Medical Imaging Suite. For more information, refer to Saving A Region.

Only TIFF and DICOM file formats are capable of saving images that have been window-leveled. Images can be window-leveled by calling RasterImage.WindowLevel and specifying RasterWindowLevelMode.PaintAndProcessing, by using the WindowLevelCommand or by loading an image from a file format that supports Window Leveling. If a window-leveled image is saved as any other file format, the image data will be converted before being saved. For more information, refer to Saving Window-Leveled Images.

Use the CodecsSaveOptions class to set up other save options parameters before calling this method.

This method supports signed data images, but only DICOM and TIFF formats support signed data. This method will throw an exception if you attempt to save a signed image to a format other than DICOM or TIFF.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also