Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF 21.4 te permite combinar imágenes. El método Merge Images verifica el contenido de una carpeta específica y trabaja con el tipo de archivos especificado en ella. Al trabajar con la combinación de imágenes, especificamos ‘inputImagesStreams’, el formato de imagen y el modo de combinación de imágenes (por ejemplo, vertical) de nuestro archivo. Luego guardamos nuestro resultado en FileOutputStream.
Sigue el siguiente fragmento de código para resolver tu tarea:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void MergeImages01()
{
var dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Updated to use dynamic path
// Get all image files matching the pattern "MergeImages*.jpg"
var fileStreams = Directory.GetFiles(dataDir, "MergeImages*.jpg")
.OrderBy(f => f)
.Select(f => File.OpenRead(f))
.Cast<Stream>()
.ToList();
using (Stream inputStream = Aspose.Pdf.Facades.PdfConverter.MergeImages(fileStreams, Aspose.Pdf.Drawing.ImageFormat.Jpeg, ImageMergeMode.Vertical, 1, 1))
using (FileStream outputStream = new FileStream(dataDir + "MergeImages_out.jpg", FileMode.Create))
{
// Copy merged images to the output file
inputStream.CopyTo(outputStream);
}
}
El segundo ejemplo funciona igual que el anterior, pero las imágenes combinadas se guardarán horizontalmente.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void MergeImages02()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Get all image files matching the pattern "MergeImages*.jpg"
var fileStreams = Directory.GetFiles(dataDir, "MergeImages*.jpg")
.OrderBy(f => f)
.Select(f => File.OpenRead(f))
.Cast<Stream>()
.ToList();
using (Stream inputStream =
Aspose.Pdf.Facades.PdfConverter.MergeImages(fileStreams, Aspose.Pdf.Drawing.ImageFormat.Jpeg, ImageMergeMode.Horizontal, 1, 1))
using (FileStream outputStream = new FileStream(dataDir + "MergeImages02_out.jpg", FileMode.Create))
{
// Copy merged images to the output file
inputStream.CopyTo(outputStream);
}
}
En el tercer ejemplo, combinaremos las imágenes centrándolas. Dos horizontalmente, dos verticalmente.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void MergeImages03()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Get all image files matching the pattern "MergeImages*.jpg"
var fileStreams = Directory.GetFiles(dataDir, "MergeImages*.jpg")
.OrderBy(f => f)
.Select(f => File.OpenRead(f))
.Cast<Stream>()
.ToList();
using (Stream inputStream =
Aspose.Pdf.Facades.PdfConverter.MergeImages(fileStreams, Aspose.Pdf.Drawing.ImageFormat.Jpeg, ImageMergeMode.Center, 2, 2))
using (FileStream outputStream = new FileStream(dataDir + "MergeImages03_out.jpg", FileMode.Create))
{
// Copy merged images to the output file
inputStream.CopyTo(outputStream);
}
}
Además, Aspose.PDF para Java te presenta la oportunidad de combinar imágenes y guardarlas en formato Tiff, utilizando el MergeImagesAsTiff Method.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void MergeImages04()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Get all image files matching the pattern "MergeImages*.jpg"
var fileStreams = Directory.GetFiles(dataDir, "MergeImages*.jpg")
.OrderBy(f => f)
.Select(f => File.OpenRead(f))
.Cast<Stream>()
.ToList();
using (Stream inputStream =
Aspose.Pdf.Facades.PdfConverter.MergeImagesAsTiff(fileStreams))
using (FileStream outputStream = new FileStream(dataDir + "MergeImages_out.tiff", FileMode.Create))
{
// Copy merged images to the output file
inputStream.CopyTo(outputStream);
}
}
Para guardar las imágenes combinadas como una sola imagen en la página PDF, las colocamos en el imageStream, colocamos el resultado en la página con el método addImage, donde especificamos las coordenadas donde queremos colocarlas.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void MergeImages05()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Get all image files matching the pattern "MergeImages*.jpg"
var fileStreams = Directory.GetFiles(dataDir, "MergeImages*.jpg")
.OrderBy(f => f)
.Select(f => File.OpenRead(f))
.Cast<Stream>()
.ToList();
using (Stream inputStream =
Aspose.Pdf.Facades.PdfConverter.MergeImages(fileStreams, Aspose.Pdf.Drawing.ImageFormat.Jpeg, ImageMergeMode.Vertical, 1, 1))
using (MemoryStream outputStream = new MemoryStream()) // Output to MemoryStream
{
// Copy merged images to the MemoryStream
inputStream.CopyTo(outputStream);
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Add the image from the MemoryStream to the page
page.AddImage(outputStream, new Aspose.Pdf.Rectangle(10, 120, 400, 720));
// Save PDF document
document.Save(dataDir + "MergeImages_out.pdf");
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.