Saves a stamp in an existing file with specific options.
public void SaveStamp(Leadtools.RasterImage image,string fileName,int firstPage,int lastPage,int firstSavePageNumber,Leadtools.Codecs.CodecsSavePageMode pageMode)
Public Overloads Sub SaveStamp( _ByVal image As Leadtools.RasterImage, _ByVal fileName As String, _ByVal firstPage As Integer, _ByVal lastPage As Integer, _ByVal firstSavePageNumber As Integer, _ByVal pageMode As Leadtools.Codecs.CodecsSavePageMode _)
public void SaveStamp(Leadtools.RasterImage image,string fileName,int firstPage,int lastPage,int firstSavePageNumber,Leadtools.Codecs.CodecsSavePageMode pageMode)
- (BOOL) saveStamp:(LTRasterImage *)imagefile:(NSString *)filefirstPage:(NSInteger)firstPagelastPage:(NSInteger)lastPagefirstSavePageNumber:(NSInteger)firstSavePageNumberpageMode:(LTCodecsSavePageMode)pageModeerror:(NSError **)error
function Leadtools.Codecs.RasterCodecs.SaveStamp(RasterImage,String,Int32,Int32,Int32,CodecsSavePageMode)(image ,fileName ,firstPage ,lastPage ,firstSavePageNumber ,pageMode)
public:void SaveStamp(Leadtools.RasterImage^ image,String^ fileName,int firstPage,int lastPage,int firstSavePageNumber,Leadtools.Codecs.CodecsSavePageMode pageMode)
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 multi-page formats. This can be one of the following:
| Value | Meaning |
|---|---|
| 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. |
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).
NOTE: At this time, there are no multi-page formats that support stamps.
This example will add a stamp to an existing file before reading it back
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;using LeadtoolsExamples.Common;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 nameRasterImage image = codecs.Load(srcFileName);// Save as the destination imagecodecs.Save(image, destFileName, RasterImageFormat.Cmp, 24);// Resize the image to fit into 128 by 128 pixels keeping the aspect ratioLeadRect 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 middlestring 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 filecodecs.SaveStamp(image, destFileName, 1, 1, 1, CodecsSavePageMode.Overwrite);image.Dispose();// Load the stamp from the file and save it into another fileimage = codecs.ReadStamp(destFileName, 1);codecs.Save(image, stampFileName, RasterImageFormat.Bmp, 24);image.Dispose();// Clean upcodecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingImports Leadtools.SvgPublic Sub StampExample()Dim codecs As RasterCodecs = New RasterCodecs()Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithCustomStamp.cmp")Dim stampFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Stamp.bmp")' Load the source file nameDim image As RasterImage = codecs.Load(srcFileName)' Save as the destination imagecodecs.Save(image, destFileName, RasterImageFormat.Cmp, 24)' Resize the image to fit into 128 by 128 pixels keeping the aspect ratioDim rc As LeadRect = New LeadRect(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.Widthcommand.Height = rc.Heightcommand.Flags = RasterSizeFlags.Nonecommand.Run(image)' Add the word "Stamp" on the image at the middleDim message As String = "Stamp"Using rg As RasterGraphics = RasterImagePainter.CreateGraphics(image)Using sf As New System.Drawing.StringFormat()sf.Alignment = System.Drawing.StringAlignment.Centersf.LineAlignment = System.Drawing.StringAlignment.CenterUsing f As New System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold)Dim rcDraw As New System.Drawing.Rectangle(rc.X, rc.Y, rc.Width, rc.Height)rg.Graphics.DrawString(message, f, System.Drawing.Brushes.Yellow, rcDraw, sf)End UsingEnd UsingEnd Using' Now set this image as the stamp for this filecodecs.SaveStamp(image, destFileName, 1, 1, 1, CodecsSavePageMode.Overwrite)image.Dispose()' Load the stamp from the file and save it into another fileimage = codecs.ReadStamp(destFileName, 1)codecs.Save(image, stampFileName, RasterImageFormat.Bmp, 24)image.Dispose()' Clean upcodecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Windows.Media;private void StampExample(RasterImage image, Stream outStreamFileWithStamp, Stream outStreamStampOnly){RasterCodecs codecs = new RasterCodecs();// Save as the destination imagecodecs.Save(image, outStreamFileWithStamp, RasterImageFormat.Cmp, 24);// Resize the image to fit into 128 by 128 pixels keeping the aspect ratioLeadRect 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 middlestring message = "Stamp";// To add "Stamp", we will create a WriteableBitmap from the RasterImage// then add a canvas and a text block on top of it// Create a writeable bitmap from the image sourceWriteableBitmap bitmap = new WriteableBitmap(image.ImageWidth, image.ImageHeight);// The white background canvasCanvas canvas = new Canvas();canvas.Width = image.ImageWidth;canvas.Height = image.ImageHeight;// Get the RasterImage as an ImageSourceImageSource source = RasterImageConverter.ConvertToSource(image, ConvertToSourceOptions.UseSetSource);// The image for the ImageSourceImage img = new Image();img.Source = source;// The black text blockTextBlock textBlock = new TextBlock();textBlock.FontFamily = new FontFamily("Arial");textBlock.FontSize = 20;textBlock.Text = message;textBlock.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));// Add the image source and the text blockcanvas.Children.Add(img);canvas.Children.Add(textBlock);// Center the textdouble left = (canvas.Width - textBlock.ActualWidth) / 2;double top = (canvas.Height - textBlock.ActualHeight) / 2;textBlock.SetValue(Canvas.LeftProperty, left);textBlock.SetValue(Canvas.TopProperty, top);// Renderbitmap.Render(canvas, null);bitmap.Invalidate();image.Dispose();// Re-create the RasterImage from the WriteableBitmapimage = RasterImageConverter.ConvertFromSource(bitmap, ConvertFromSourceOptions.None);// stamp has to be 24-bit, so convert it backColorResolutionCommand cmd = new ColorResolutionCommand();cmd.BitsPerPixel = 24;cmd.Run(image);// This image contains the stamp, save it to the output streamcodecs.SaveStamp(image, outStreamFileWithStamp);image.Dispose();// Load the stamp from the file and save it to the other output streamimage = codecs.ReadStamp(outStreamFileWithStamp, 1);codecs.Save(image, outStreamStampOnly, RasterImageFormat.Bmp, 24);image.Dispose();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPrivate Sub StampExample(ByVal image As RasterImage, ByVal outStreamFileWithStamp As Stream, ByVal outStreamStampOnly As Stream)Dim codecs As RasterCodecs = New RasterCodecs()' Save as the destination imagecodecs.Save(image, outStreamFileWithStamp, RasterImageFormat.Cmp, 24)' Resize the image to fit into 128 by 128 pixels keeping the aspect ratioDim rc As LeadRect = New LeadRect(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.Widthcommand.Height = rc.Heightcommand.Flags = RasterSizeFlags.Nonecommand.Run(image)' Add the word "Stamp" on the image at the middleDim message As String = "Stamp"' To add "Stamp", we will create a WriteableBitmap from the RasterImage' then add a canvas and a text block on top of it' Create a writeable bitmap from the image sourceDim bitmap As WriteableBitmap = New WriteableBitmap(image.ImageWidth, image.ImageHeight)' The white background canvasDim canvas As Canvas = New Canvas()canvas.Width = image.ImageWidthcanvas.Height = image.ImageHeight' Get the RasterImage as an ImageSourceDim source As ImageSource = RasterImageConverter.ConvertToSource(image, ConvertToSourceOptions.UseSetSource)' The image for the ImageSourceDim img As Image = New Image()img.Source = source' The black text blockDim textBlock As TextBlock = New TextBlock()textBlock.FontFamily = New FontFamily("Arial")textBlock.FontSize = 20textBlock.Text = messagetextBlock.Foreground = New SolidColorBrush(Color.FromArgb(255, 0, 0, 0))' Add the image source and the text blockcanvas.Children.Add(img)canvas.Children.Add(textBlock)' Center the textDim left As Double = (canvas.Width - textBlock.ActualWidth) / 2Dim top As Double = (canvas.Height - textBlock.ActualHeight) / 2textBlock.SetValue(canvas.LeftProperty, left)textBlock.SetValue(canvas.TopProperty, top)' Renderbitmap.Render(canvas, Nothing)bitmap.Invalidate()image.Dispose()' Re-create the RasterImage from the WriteableBitmapimage = RasterImageConverter.ConvertFromSource(bitmap, ConvertFromSourceOptions.None)' stamp has to be 24-bit, so convert it backDim cmd As ColorResolutionCommand = New ColorResolutionCommand()cmd.BitsPerPixel = 24cmd.Run(image)' This image contains the stamp, save it to the output streamcodecs.SaveStamp(image, outStreamFileWithStamp)image.Dispose()' Load the stamp from the file and save it to the other output streamimage = codecs.ReadStamp(outStreamFileWithStamp, 1)codecs.Save(image, outStreamStampOnly, RasterImageFormat.Bmp, 24)image.Dispose()End Sub
|
Products |
Support |
Feedback: SaveStamp(RasterImage,String,Int32,Int32,Int32,CodecsSavePageMode) Method - Leadtools.Codecs |
Introduction |
Help Version 19.0.2017.6.16
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.