←Select platform

SaveStamp(RasterImage,Stream) Method

Summary
Saves a stamp in an existing stream with default options.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void SaveStamp( 
   RasterImage image, 
   Stream stream 
) 
- (BOOL)saveStamp:(LTRasterImage *)image  
           stream:(LTLeadStream *)stream  
            error:(NSError **)error 
public void saveStamp(RasterImage image, ILeadStream stream) 
public: 
void SaveStamp(  
   RasterImage^ image, 
   Stream^ stream 
)  
def SaveStamp(self,image,stream): 

Parameters

image
The RasterImage object that contain the thumbnail (stamp) image.

stream
A Stream containing the data of an existing image file.

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.

Example
C#
Java
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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
public void stampExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Image2.cmp"); 
   String stampFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1_LoadFileTile2.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.getImageWidth(), image.getImageHeight(), rc, 
         RasterPaintSizeMode.FIT_ALWAYS, RasterPaintAlignMode.NEAR, RasterPaintAlignMode.NEAR); 
 
   SizeCommand command = new SizeCommand(); 
   command.setWidth(rc.getWidth()); 
   command.setHeight(rc.getHeight()); 
   command.setFlags(RasterSizeFlags.NONE.getValue()); 
   command.run(image); 
 
   // Add the word "Stamp" on the image at the middle 
   String message = "Stamp"; 
 
   ILeadStream ls = LeadStreamFactory.create(destFileName); 
 
   DrwEngine drwEngine = new DrwEngine(DrwEngineType.OPEN_GL, image); 
   DrwStringFormat sf = drwEngine.newStringFormat( 
         DrwAlignment.CENTER, 
         DrwAlignment.CENTER, 
         DrwStringFormatFlags.NONE.getValue()); 
   DrwFont f = drwEngine.newFont("Arial", 20, DrwFontStyle.BOLD.getValue()); 
 
   drwEngine.drawString(message, f, (DrwBrush) drwEngine.newSolidBrush(RasterColor.BLACK), rc.toLeadRectD(), sf); 
 
   // Now set this image as the stamp for this file 
   codecs.saveStamp(image, ls, 1, 1, 1, CodecsSavePageMode.OVERWRITE); 
   image.dispose(); 
 
   // Load the stamp from the file and save it into another file 
   image = codecs.readStamp(ls, 1); 
 
   codecs.save(image, stampFileName, RasterImageFormat.BMP, 24); 
   assertTrue("File unsuccessfully saved to" + stampFileName, (new File(stampFileName)).exists()); 
 
   image.dispose(); 
 
   // Clean up 
   codecs.dispose(); 
} 
Requirements

Target Platforms

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

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