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




image
The RasterImage object that contain the thumbnail (stamp) image.
fileName
A String containing the name of an existing image file.
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 a stamp in an existing file with specific options.

Syntax

Visual Basic (Declaration) 
Overloads Public Sub SaveStamp( _
   ByVal image As RasterImage, _
   ByVal fileName As String, _
   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 firstPage As Integer
Dim lastPage As Integer
Dim firstSavePageNumber As Integer
Dim pageMode As CodecsSavePageMode
 
instance.SaveStamp(image, fileName, firstPage, lastPage, firstSavePageNumber, pageMode)
C# 
public void SaveStamp( 
   RasterImage image,
   string fileName,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode
)
Managed Extensions for C++ 
public: void SaveStamp( 
   RasterImage image,
   string* fileName,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode
) 
C++/CLI 
public:
void SaveStamp( 
   RasterImage image,
   String^ fileName,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode
) 

Parameters

image
The RasterImage object that contain the thumbnail (stamp) image.
fileName
A String containing the name of an existing image file.
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.Stamp
      Public Sub StampExample()
         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_WithCustomStamp.cmp"
         Dim stampFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_Stamp.bmp"

         ' Load the source file name
         Dim image As RasterImage = codecs.Load(srcFileName)

         ' Save as the destination image
         codecs.Save(image, destFileName, RasterImageFormat.Cmp, 24)

         ' Resize the image to fit into 128 by 128 pixels keeping the aspect ratio
         Dim rc As Rectangle = New Rectangle(0, 0, 128, 128)
         rc = RasterImage.CalculatePaintModeRectangle(image.ImageWidth, image.ImageHeight, rc, RasterPaintSizeMode.FitAlways, RasterPaintAlignMode.Near, RasterPaintAlignMode.Near)

         Dim command As SizeCommand = New SizeCommand()
         command.Width = rc.Width
         command.Height = rc.Height
         command.Flags = RasterSizeFlags.None
         command.Run(image)

         ' Add the word "Stamp" on the image at the middle
         Dim message As String = "Stamp"

         Dim container As RasterImageGdiPlusGraphicsContainer = image.CreateGdiPlusGraphics()
         Dim sf As StringFormat = New StringFormat()
         sf.Alignment = StringAlignment.Center
         sf.LineAlignment = StringAlignment.Center
         Dim f As Font = New Font("Arial", 20, FontStyle.Bold)
         container.Graphics.DrawString(message, f, Brushes.Yellow, rc, sf)
         sf.Dispose()
         f.Dispose()
         container.Dispose()

         ' Now set this image as the stamp for this file
         codecs.SaveStamp(image, destFileName, 1, 1, 1, CodecsSavePageMode.Overwrite)
         image.Dispose()

         ' Load the stamp from the file and save it into another file
         image = codecs.ReadStamp(destFileName, 1)
         codecs.Save(image, stampFileName, RasterImageFormat.Bmp, 24)
         image.Dispose()

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub
C#Copy Code
RasterCodecs.Stamp 
      public void StampExample() 
      { 
         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_WithCustomStamp.cmp"; 
         string stampFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_Stamp.bmp"; 
 
         // Load the source file name 
         RasterImage image = codecs.Load(srcFileName); 
 
         // Save as the destination image 
         codecs.Save(image, destFileName, RasterImageFormat.Cmp, 24); 
 
         // Resize the image to fit into 128 by 128 pixels keeping the aspect ratio 
         Rectangle rc = new Rectangle(0, 0, 128, 128); 
         rc = RasterImage.CalculatePaintModeRectangle( 
            image.ImageWidth, 
            image.ImageHeight, 
            rc, 
            RasterPaintSizeMode.FitAlways, 
            RasterPaintAlignMode.Near, 
            RasterPaintAlignMode.Near); 
 
         SizeCommand command = new SizeCommand(); 
         command.Width = rc.Width; 
         command.Height = rc.Height; 
         command.Flags = RasterSizeFlags.None; 
         command.Run(image); 
 
         // Add the word "Stamp" on the image at the middle 
         string message = "Stamp"; 
 
         RasterImageGdiPlusGraphicsContainer container = image.CreateGdiPlusGraphics(); 
         StringFormat sf = new StringFormat(); 
         sf.Alignment = StringAlignment.Center; 
         sf.LineAlignment = StringAlignment.Center; 
         Font f = new Font("Arial", 20, FontStyle.Bold); 
         container.Graphics.DrawString(message, f, Brushes.Yellow, rc, sf); 
         sf.Dispose(); 
         f.Dispose(); 
         container.Dispose(); 
 
         // Now set this image as the stamp for this file 
         codecs.SaveStamp(image, destFileName, 1, 1, 1, CodecsSavePageMode.Overwrite); 
         image.Dispose(); 
 
         // Load the stamp from the file and save it into another file 
         image = codecs.ReadStamp(destFileName, 1); 
         codecs.Save(image, stampFileName, RasterImageFormat.Bmp, 24); 
         image.Dispose(); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      }

Remarks

The stamp will be written to last page in the file. If that page already has a stamp, it will be overwritten; If the file to which the stamp is being written does not exist, an exception will occur.

This method works for regular JPEG files and Exif JPEG files. For regular JPEG files, the stamp saved is always uncompressed and can be 8 or 24 bits per pixel. The stamp can be any width and height, but the stamp data and stamp header must completely fit in an APP0 marker. Therefore, the size must be less than 64k bytes (0xFFFF).

For Exif JPEG files, the stamps can be uncompressed or JPEG compressed and must be 24 bits per pixel. Exif JPEG stamps are supposed to be 160 x 120. However, LEADTOOLS can save and read Exif JPEG stamps of other dimensions. The stamp, along with other information such as the TIFF_HEADER, 0th IFD, 1st IFD, etc. must completely fit in an APP1 marker. Therefore, the size must be less than 64k bytes (0xFFFF).

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