public static bool FormatSupportsMultipageSave(
RasterImageFormat format
)
Public Shared Function FormatSupportsMultipageSave( _
ByVal format As RasterImageFormat _
) As Boolean
public:
static bool FormatSupportsMultipageSave(
RasterImageFormat format
)
format
Format to check.
true if the image file format specified by format supports multipage save operations.
This example will try to save a multipage file to disk, if the format supports multipage files, then it will create a single output file, otherwise, multiple files (for each page) will be created.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Svg;
private static void SaveMultiPageFile(RasterCodecs rasterCodecs, RasterImage multiPageImage, string outputFile, RasterImageFormat format)
{
// Check if the image has multi-ple pages and the format supports multi-page
if (multiPageImage.PageCount > 1 && RasterCodecs.FormatSupportsMultipageSave(format))
{
// Yes, just save the file
rasterCodecs.Save(multiPageImage, outputFile, format, 0, 1, -1, 1, CodecsSavePageMode.Overwrite);
}
else
{
// No, we need to save each page in a separate file
int originalPageNumber = multiPageImage.Page;
for (int pageNumber = 1; pageNumber <= multiPageImage.PageCount; pageNumber++)
{
// Get the new file name
string name = Path.GetFileNameWithoutExtension(outputFile) + "_page" + pageNumber.ToString();
name = Path.ChangeExtension(name, Path.GetExtension(outputFile));
string pageFile = Path.Combine(Path.GetDirectoryName(outputFile), name);
// Save this page
multiPageImage.Page = pageNumber;
rasterCodecs.Save(multiPageImage, pageFile, format, 0);
}
multiPageImage.Page = originalPageNumber;
}
}
public static void FormatSupportsMultipageSaveExample()
{
string inDir = LEAD_VARS.ImagesDir;
string outDir = Path.Combine(inDir, @"FormatSupportsMultipageSave");
if (!Directory.Exists(outDir))
Directory.CreateDirectory(outDir);
using (RasterCodecs rasterCodecs = new RasterCodecs())
{
// Create a multi-page image
using (RasterImage multiPageImage = GetMultipageImage(rasterCodecs, inDir))
{
// Save the image as TIF, this should create a single file
SaveMultiPageFile(rasterCodecs, multiPageImage, Path.Combine(outDir, "out.tif"), RasterImageFormat.Tif);
// Save the image as PNG, this should create multiple files (one for each page)
SaveMultiPageFile(rasterCodecs, multiPageImage, Path.Combine(outDir, "out.png"), RasterImageFormat.Png);
}
}
}
private static RasterImage GetMultipageImage(RasterCodecs rasterCodecs, string inDir)
{
// Create a multi-page image from some known LEADTOOLS images
RasterImage multiPageImage = null;
for (int imageNumber = 1; imageNumber <= 4; imageNumber++)
{
string fileName = Path.Combine(inDir, "Ocr" + imageNumber.ToString() + ".tif");
RasterImage pageImage = rasterCodecs.Load(fileName, 1);
if (multiPageImage == null)
{
multiPageImage = pageImage;
}
else
{
multiPageImage.AddPage(pageImage);
pageImage.Dispose();
}
}
return multiPageImage;
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS21\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