←Select platform

SaveStamp(RasterImage,string,int,int,int,CodecsSavePageMode) Method

Summary
Saves a stamp in an existing file with specific options.
Syntax
C#
Objective-C
C++/CLI
Python
- (BOOL)  saveStamp:(LTRasterImage *)image  
               file:(NSString *)file  
          firstPage:(NSInteger)firstPage  
           lastPage:(NSInteger)lastPage  
firstSavePageNumber:(NSInteger)firstSavePageNumber  
           pageMode:(LTCodecsSavePageMode)pageMode  
              error:(NSError **)error 
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:

Value Description
CodecsSavePageMode.Append Append 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.Insert Insert the new page(s) at the index specified by [firstSavePageNumber].
CodecsSavePageMode.Replace Replace the page(s) starting at the index specified by [firstSavePageNumber].
CodecsSavePageMode.Overwrite Overwrite the page(s) starting at the index specified by [firstSavePageNumber].
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 function works for JPEG, Exif, PNG and TIF file formats. 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).

For PNG files, the stamp will be saved uncompressed. The width and height are not limited but the bitmap should 24-bit.

Note

At this time, there are no multipage formats that support stamps.

Example

This example will add a stamp to an existing file before reading it back.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
 
public void StampExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithCustomStamp.cmp"); 
   string stampFileName = Path.Combine(LEAD_VARS.ImagesDir, "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 
   LeadRect rc = new LeadRect(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"; 
 
   using (Leadtools.Drawing.RasterGraphics rg = Leadtools.Drawing.RasterImagePainter.CreateGraphics(image)) 
   { 
      using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat()) 
      { 
         sf.Alignment = System.Drawing.StringAlignment.Center; 
         sf.LineAlignment = System.Drawing.StringAlignment.Center; 
         using (System.Drawing.Font f = new System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold)) 
         { 
            System.Drawing.Rectangle rcDraw = new System.Drawing.Rectangle(rc.X, rc.Y, rc.Width, rc.Height); 
            rg.Graphics.DrawString(message, f, System.Drawing.Brushes.Yellow, rcDraw, sf); 
         } 
      } 
   } 
 
   // 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(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.