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




image
The RasterImage object that holds the image data.
fileName
A String containing the output file name.
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.
firstPage
1-based index of the first page in image to save.
lastPage
1-based index of the last page in image to save. Pass -1 to save from firstPage to the last page in image.
firstSavePageNumber
1-based index of the first output page. If the output file already exists, then this parameter lets you control which pages to overwrite and/or where to append the new pages.
pageMode

Determines how to handle the page when saving to multipage formats. This can be one of the following:

ValueMeaning
CodecsSavePageMode.AppendAppend the new page(s) to the end of the file. If the file does not exist, this option will create the file and add the pages to it. firstSavePageNumber is not used.
CodecsSavePageMode.InsertInsert the new page(s) at the index specified by firstSavePageNumber.
CodecsSavePageMode.ReplaceReplace the page(s) starting at the index specified by firstSavePageNumber.
CodecsSavePageMode.OverwriteOverwrite the page(s) starting at the index specified by firstSavePageNumber.
CodecsSavePageMode.AppendAppend the new page(s) to the end of the file. If the file does not exist, this option will create the file and add the pages to it.

Saves one or more pages of a RasterImage to a file in any of the supported compressed or uncompressed formats.

Syntax

Visual Basic (Declaration) 
Overloads Public Sub Save( _
   ByVal image As RasterImage, _
   ByVal fileName As String, _
   ByVal format As RasterImageFormat, _
   ByVal bitsPerPixel As Integer, _
   ByVal firstPage As Integer, _
   ByVal lastPage As Integer, _
   ByVal firstSavePageNumber As Integer, _
   ByVal pageMode As CodecsSavePageMode _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterCodecs
Dim image As RasterImage
Dim fileName As String
Dim format As RasterImageFormat
Dim bitsPerPixel As Integer
Dim firstPage As Integer
Dim lastPage As Integer
Dim firstSavePageNumber As Integer
Dim pageMode As CodecsSavePageMode
 
instance.Save(image, fileName, format, bitsPerPixel, firstPage, lastPage, firstSavePageNumber, pageMode)
C# 
public void Save( 
   RasterImage image,
   string fileName,
   RasterImageFormat format,
   int bitsPerPixel,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode
)
Managed Extensions for C++ 
public: void Save( 
   RasterImage image,
   string* fileName,
   RasterImageFormat format,
   int bitsPerPixel,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode
) 
C++/CLI 
public:
void Save( 
   RasterImage image,
   String^ fileName,
   RasterImageFormat format,
   int bitsPerPixel,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode
) 

Parameters

image
The RasterImage object that holds the image data.
fileName
A String containing the output file name.
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.
firstPage
1-based index of the first page in image to save.
lastPage
1-based index of the last page in image to save. Pass -1 to save from firstPage to the last page in image.
firstSavePageNumber
1-based index of the first output page. If the output file already exists, then this parameter lets you control which pages to overwrite and/or where to append the new pages.
pageMode

Determines how to handle the page when saving to multipage formats. This can be one of the following:

ValueMeaning
CodecsSavePageMode.AppendAppend the new page(s) to the end of the file. If the file does not exist, this option will create the file and add the pages to it. firstSavePageNumber is not used.
CodecsSavePageMode.InsertInsert the new page(s) at the index specified by firstSavePageNumber.
CodecsSavePageMode.ReplaceReplace the page(s) starting at the index specified by firstSavePageNumber.
CodecsSavePageMode.OverwriteOverwrite the page(s) starting at the index specified by firstSavePageNumber.
CodecsSavePageMode.AppendAppend the new page(s) to the end of the file. If the file does not exist, this option will create the file and add the pages to it.

Example

Visual BasicCopy Code
RasterCodecs.Save(RasterImage, string, RasterImageFormat, int, int, int, int, CodecsSavePageMode)
      Public Sub SaveFile2Example()
         RasterCodecs.Startup()
         Dim codecs As RasterCodecs = New RasterCodecs()

         Dim destFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_SaveFile2.tif"

         ' Create a RasterImage with 4 pages containing text showing the page number
         Dim image As RasterImage = Nothing

         Dim f As Font = New Font("Arial", 36, FontStyle.Bold)
         Dim btmp As Bitmap = New Bitmap(320, 200)
         Dim rc As Rectangle = New Rectangle(0, 0, btmp.Width, btmp.Height)
         Dim sf As StringFormat = New StringFormat()
         sf.Alignment = StringAlignment.Center
         sf.LineAlignment = StringAlignment.Center

         Const pageCount As Integer = 4
         For i As Integer = 1 To pageCount
            ' Create a GDI+ bitmap with the text
            Dim text As String = "Page " & i

            Dim g As Graphics = Graphics.FromImage(btmp)
            g.FillRectangle(Brushes.White, rc)
            g.DrawString(text, f, Brushes.Black, rc, sf)
            g.Dispose()

            Dim tempImage As RasterImage = New RasterImage(btmp)

            If image Is Nothing Then
               image = tempImage
            Else
               image.AddPage(tempImage)
            End If
         Next i

         sf.Dispose()
         btmp.Dispose()

         ' Save all the pages to the file
         ' The file should have 4 pages now: 1, 2, 3, 4
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, pageCount, 1, CodecsSavePageMode.Overwrite)
         image.Dispose()

         ' Load the 3rd page and insert it as the second
         ' The file should have 5 pages now: 1, 3, 2, 3, 4
         image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 3, 3)
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 2, CodecsSavePageMode.Insert)
         image.Dispose()

         ' Load the last page, and insert it as the first
         ' The file should have 5 pages now: 4, 1, 3, 2, 3, 4
         image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 5, 5)
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert)
         image.Dispose()

         ' Replace the 5th page with the 2nd
         ' The file should have 5 pages now: 4, 1, 3, 2, 1, 4
         image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 2, 2)
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 5, CodecsSavePageMode.Replace)
         image.Dispose()

         ' Delete the 2nd and 6th pages
         ' The file should have 5 pages now: 4, 3, 2, 1
         codecs.DeletePage(destFileName, 2)
         ' Notice, -1 because we already deleted a page, so 6th page is not 5th
         codecs.DeletePage(destFileName, 6 - 1)

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub
C#Copy Code
RasterCodecs.Save(RasterImage, string, RasterImageFormat, int, int, int, int, CodecsSavePageMode) 
      public void SaveFile2Example() 
      { 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
 
         string destFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_SaveFile2.tif"; 
 
         // Create a RasterImage with 4 pages containing text showing the page number 
         RasterImage image = null; 
 
         Font f = new Font("Arial", 36, FontStyle.Bold); 
         Bitmap btmp = new Bitmap(320, 200); 
         Rectangle rc = new Rectangle(0, 0, btmp.Width, btmp.Height); 
         StringFormat sf = new StringFormat(); 
         sf.Alignment = StringAlignment.Center; 
         sf.LineAlignment = StringAlignment.Center; 
 
         const int pageCount = 4; 
         for(int i = 1; i <= pageCount; i++) 
         { 
            // Create a GDI+ bitmap with the text 
            string text = "Page " + i; 
 
            Graphics g = Graphics.FromImage(btmp); 
            g.FillRectangle(Brushes.White, rc); 
            g.DrawString(text, f, Brushes.Black, rc, sf); 
            g.Dispose(); 
 
            RasterImage tempImage = new RasterImage(btmp); 
 
            if(image == null) 
               image = tempImage; 
            else 
               image.AddPage(tempImage); 
         } 
 
         sf.Dispose(); 
         btmp.Dispose(); 
 
         // Save all the pages to the file 
         // The file should have 4 pages now: 1, 2, 3, 4 
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, pageCount, 1, CodecsSavePageMode.Overwrite); 
         image.Dispose(); 
 
         // Load the 3rd page and insert it as the second 
         // The file should have 5 pages now: 1, 3, 2, 3, 4 
         image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 3, 3); 
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 2, CodecsSavePageMode.Insert); 
         image.Dispose(); 
 
         // Load the last page, and insert it as the first 
         // The file should have 5 pages now: 4, 1, 3, 2, 3, 4 
         image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 5, 5); 
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert); 
         image.Dispose(); 
 
         // Replace the 5th page with the 2nd 
         // The file should have 5 pages now: 4, 1, 3, 2, 1, 4 
         image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 2, 2); 
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 5, CodecsSavePageMode.Replace); 
         image.Dispose(); 
 
         // Delete the 2nd and 6th pages 
         // The file should have 5 pages now: 4, 3, 2, 1 
         codecs.DeletePage(destFileName, 2); 
         // Notice, -1 because we already deleted a page, so 6th page is not 5th 
         codecs.DeletePage(destFileName, 6 - 1); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      }

Remarks

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. For more information, refer to Saving A Region. 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. ///

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