public void CompactFile(
Stream srcStream,
Stream destStream,
int pages,
int srcStartPage,
bool useSrcIfd,
int srcIfd,
int destStartPage,
bool useDestIfd,
int destIfd,
CodecsSavePageMode pageMode,
bool noSubFileType,
bool motorolaOrder
)
public:
void CompactFile(
Stream^ srcStream,
Stream^ destStream,
int pages,
int srcStartPage,
bool useSrcIfd,
int srcIfd,
int destStartPage,
bool useDestIfd,
int destIfd,
CodecsSavePageMode pageMode,
bool noSubFileType,
bool motorolaOrder
)
def CompactFile(self,srcStream,destStream,pages,srcStartPage,useSrcIfd,srcIfd,destStartPage,useDestIfd,destIfd,pageMode,noSubFileType,motorolaOrder):
srcStream
A Stream containing the data of the file being compacted. All the pages will be read from this stream.
destStream
A Stream that will contain the written data.
pages
Value that represents the number of pages to copy. Use 0 to copy all the pages. If pages is > 0, only pages will be copied to destStream.
srcStartPage
Specifies the start page in the source stream. Page 1 is the first page, page 2 is the second page, etc. The pages will be read starting with this page.
useSrcIfd
true to use srcIfd as the stream offset of the first page. false to use srcStartPage.
srcIfd
Offset into the source stream for the start page. Used only if useSrcIfd is true.
All pages will be relative to that page. (Note that this might not be the first physical page in the stream). This is a common technique for manipulating files with thousands of pages.
destStartPage
0 to overwrite destStream. <>0 to append the pages to the end of the stream.
useDestIfd
true to use destIfd as the stream offset of the first page. false to use destStartPage.
destIfd
Offset into the destination stream for the start page. Used only if useDestIfd is true.
All pages will be relative to that page. (Note that this might not be the first physical page in the stream). This is a common technique for manipulating files with thousands of pages.
pageMode
Flag which indicates the save page mode.
Value | Meaning |
---|---|
CodecsSavePageMode.Insert | All pages are inserted before destStartPage . |
CodecsSavePageMode.Replace | Pages in destStream are replaced beginning with destStartPage . |
noSubFileType
true to have the TGSUBFILETYPE tag stripped from all pages in the destination file.
motorolaOrder
true to save pages in Motorola byte order. false to save pages in Intel byte order. This only applies when creating a new file. When updating existing files, the byte order of the original file is used.
This method can also be used to copy or extract one or more pages from a TIFF file and copy them without recompression to another TIFF file. Whenever you save an image containing a region as a TIFF file format, the region is also saved. Note, however, that the ability to save a region inside a TIFF file must be unlocked. This requires a Document Imaging or Medical Imaging toolkit.
If the source is PNG, the destination is also PNG. If the source is Exif JPEG, the destination is also Exif JPEG. For both of these formats, setting pages to 1 will discard the thumbnail if it exists.
The "ifd" settings are not useful for PNG and Exif JPEG and should not be used. They will most likely not give you the results you expect.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Svg;
public void CompactFileExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "CompactFile1_Src.tif");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "CompactFile1_Dest.tif");
// Create a RasterImage with 4 pages containing text showing the page number
RasterImage image = null;
const int pageCount = 4;
using (System.Drawing.Font f = new System.Drawing.Font("Arial", 36, System.Drawing.FontStyle.Bold))
using (System.Drawing.Bitmap btmp = new System.Drawing.Bitmap(320, 200))
using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat())
{
System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, btmp.Width, btmp.Height);
sf.Alignment = System.Drawing.StringAlignment.Center;
sf.LineAlignment = System.Drawing.StringAlignment.Center;
for (int i = 1; i <= pageCount; i++)
{
// Create a GDI+ bitmap with the text
string text = "Page " + i;
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(btmp))
{
g.FillRectangle(System.Drawing.Brushes.White, rc);
g.DrawString(text, f, System.Drawing.Brushes.Black, rc, sf);
}
RasterImage tempImage = Leadtools.Drawing.RasterImageConverter.ConvertFromImage(btmp, Leadtools.Drawing.ConvertFromImageOptions.None);
if (image == null)
image = tempImage;
else
image.AddPage(tempImage);
}
}
// Save all the pages to the file
// The file should have 4 pages now: 1, 2, 3, 4
codecs.Save(image, srcFileName, RasterImageFormat.Tif, 1, 1, pageCount, 1, CodecsSavePageMode.Overwrite);
image.Dispose();
// All the pages in the source TIFF file. This will create the destination file
codecs.CompactFile(srcFileName, destFileName, 0);
// Compact the source file again and append all the pages to the existing destination file
int pagesToAdd = 0; // 0 means all pages
int srcStartPage = 1;
int destStartPage = 5; // insert at the end
codecs.CompactFile(
srcFileName,
destFileName,
pagesToAdd,
srcStartPage,
false,
0,
destStartPage,
false,
0,
CodecsSavePageMode.Insert,
false,
false);
// Clean up
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document