MemoryStream을 사용하여 PDF를 이미지로 래스터화하기
파일 시스템을 건드리지 않고 MemoryStream을 사용하여 PDF 페이지를 이미지로 변환하는 방법은 무엇인가요?
IronPDF MemoryStream에서 PDF 문서를 불러오는 기능을 제공합니다. ( 방법) | API 참조 )
PdfDocument.ToBitmap() 메서드를 사용하여 PDF 페이지를 이미지로 내보내세요. 이 함수는 IronSoftware.Drawing.AnyBitmap 객체 배열을 반환하며, 이 객체는 추가 처리에 사용할 수 있습니다.
using IronPdf;
using System.IO;
// Example rendering PDF documents to Images or Thumbnails
using var pdf = PdfDocument.FromFile("Example.pdf");
// Convert each page of the PDF document to a bitmap image
IronSoftware.Drawing.AnyBitmap[] pageImages = pdf.ToBitmap();
foreach (var bitmap in pageImages)
{
// Use MemoryStream to handle the image data in memory
using (MemoryStream memoryStream = new MemoryStream())
{
// Export the image to MemoryStream as a PNG format
bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png);
// MemoryStream can now be used for further processing without touching the file system
// Example: Send it over a network, save to a database, etc.
}
// Dispose of the bitmap once processing is complete to free resources
bitmap.Dispose();
}
using IronPdf;
using System.IO;
// Example rendering PDF documents to Images or Thumbnails
using var pdf = PdfDocument.FromFile("Example.pdf");
// Convert each page of the PDF document to a bitmap image
IronSoftware.Drawing.AnyBitmap[] pageImages = pdf.ToBitmap();
foreach (var bitmap in pageImages)
{
// Use MemoryStream to handle the image data in memory
using (MemoryStream memoryStream = new MemoryStream())
{
// Export the image to MemoryStream as a PNG format
bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png);
// MemoryStream can now be used for further processing without touching the file system
// Example: Send it over a network, save to a database, etc.
}
// Dispose of the bitmap once processing is complete to free resources
bitmap.Dispose();
}
Imports IronPdf
Imports System.IO
' Example rendering PDF documents to Images or Thumbnails
Private pdf = PdfDocument.FromFile("Example.pdf")
' Convert each page of the PDF document to a bitmap image
Private pageImages() As IronSoftware.Drawing.AnyBitmap = pdf.ToBitmap()
For Each bitmap In pageImages
' Use MemoryStream to handle the image data in memory
Using memoryStream As New MemoryStream()
' Export the image to MemoryStream as a PNG format
bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png)
' MemoryStream can now be used for further processing without touching the file system
' Example: Send it over a network, save to a database, etc.
End Using
' Dispose of the bitmap once processing is complete to free resources
bitmap.Dispose()
Next bitmap
비트맵을 MemoryStream에 저장하는 방법에 대한 자세한 내용은 Stack Overflow의 다음 글을 참고하세요.

