IRONSOFTWAREHOME

使用 MemoryStream 將 PDF 光柵化為圖像

Curtis Chau
Curtis Chau
Updated: 2026年4月22日

如何使用 MemoryStream 將 PDF 頁面轉換為圖像,而不接觸文件系統?

IronPDF 提供從 MemoryStream 載入 PDF 文件的功能。 (How-Tos | API Reference) using 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();
}

這裡有一篇有用的 Stack Overflow 文章,提供有關將位圖保存到 MemoryStream 的更多詳細資訊。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備開始了嗎?

Nuget Downloads 20,667,543版本:2026.7剛剛發布

立即獲取您的免費30天試用密鑰
不需要信用卡或建立賬戶
C# 用於PDF的NuGet程式庫
使用NuGet安裝

版本: 2026.7

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解決方案資源管理器,右鍵點選參考,管理NuGet包
  2. 選擇瀏覽並搜尋"IronPdf"
  3. 選擇套件並安裝
C# PDF DLL
下載DLL

版本: 2026.7

立即下載

或者點擊此處下載Windows安裝程式。

  1. 下載並解壓IronPDF到類似~/Libs的位置,位於您的解決方案目錄中
  2. 在Visual Studio解決方案資源管理器,右鍵點選參考。選擇瀏覽,"IronPdf.dll"

授權從$999

有問題嗎?聯絡我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費現場演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立