LEADTOOLS画像ファイルサポート(Leadtools.Codecsアセンブリ)

フレームを表示

CodecsRasterizeDocumentLoadOptionsクラス








メンバ 
文書ファイルをラスター画像(ラスタライズ)としてロードするための設定オプションが含まれます。
オブジェクトモデル
構文
public class CodecsRasterizeDocumentLoadOptions 
'Declaration
 
Public Class CodecsRasterizeDocumentLoadOptions 
'Usage
 
Dim instance As CodecsRasterizeDocumentLoadOptions
public sealed class CodecsRasterizeDocumentLoadOptions 
@interface LTCodecsRasterizeDocumentLoadOptions : NSObject
public class CodecsRasterizeDocumentLoadOptions
function Leadtools.Codecs.CodecsRasterizeDocumentLoadOptions()
public ref class CodecsRasterizeDocumentLoadOptions 
解説

LEADTOOLSは、ラスター画像としてドキュメントをロードすることをサポートします。PDF、XP、DOCX/doc、PPTX/PPT、XLSS/XL、RTFとテキストなどの文書形式は、物理的な幅、高さまたは解像度情報を格納しません。ラスタライズと呼ばれるプロセスを通じて論理座標から物理座標までの変換を指定するのはローダー次第(この場合はRasterCodecsオブジェクト)です。

ラスタライゼーションは、ドキュメントがラスター画像に変換されるプロセスです。特定のファイルが正規のラスター画像よりもむしろ文書ファイルをディスク上で(または.NETストリームで)格納するかどうか調べるために、RasterCodecs.GetInformationRasterCodecs.GetInformationAsyncメソッドを呼び出して、CodecsDocumentImageInfo.IsDocumentFileプロパティを確認します。ここにコードスニペットがある。


             CodecsImageInfo imageInfo = rasterCodecsInstance.GetInformation(fileName, true);
             if(imageInfo.Document.IsDocumentFile)
             {
                // A document file (PDF, XPS, DOCX/DOC, PPTX/PPT, XLSS/XLS, etc), show the original document size:
                Console.WriteLine("Document file, original size is {0} by {1} {2}",
                   imageInfo.Document.PageWidth, imageInfo.Document.PageHeight, imageInfo.Document.Unit);
            
                // Your code specific to rasterization based on the original document size goes here
             }
             

文書ファイルをラスタライズするために、CodecsRasterizeDocumentLoadOptionsのプロパティを必須値に設定します。たとえば、次のコードは、解像度が300DPIで8.5×11インチのサイズにドキュメントファイルをフィットさせます。RasterCodecs.LoadまたはRasterCodecs.LoadAsyncメソッドでロードされるすべての文書ファイルが、300×300の解像度で、ほんの2550×3300ピクセルの幅/高さしか持っているというわけではありません:


             CodecsRasterizeDocumentLoadOptions rasterDocumentLoadOptions = rasterCodecsInstance.Options.RasterizeDocument.Load;
             // Set the size mode, we want to fit
             rasterDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;
             // Set the page size
             rasterDocumentLoadOptions.PageWidth = 8.5;
             rasterDocumentLoadOptions.PageHeight = 11;
             rasterDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;
             // And the resolution
             rasterDocumentLoadOptions.XResolution = 300;
             rasterDocumentLoadOptions.YResolution = 300;
            
             // Load the image
             RasterImage image = rasterCodecsInstance.Load(fileName);
            
             // Show its pixel size, it should be less than or equal to
             // 2550 by 3300 pixels (8.5 * 300 by 11 * 300)
             Console.WriteLine("Loaded image size: {0} by {1} pixels at {2} by {3}",
             image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);
             

CodecsRasterizeDocumentLoadOptionsクラスは、以下のプロパティを格納します:

プロパティ 説明
PageWidthPageHeight

結果として生じるページ幅と高さ(単位で)。結果として生じるラスター画像幅と高さの値は、現在の解像度とサイズモード値にピクセル単位で依存します。

LeftMarginTopMarginRightMarginBottomMargin

単位として単位を用いてleft、上、権利と下部余白でそのままになるマージンのサイズ。現時点では、RTFTXTドキュメントだけは、マージンをサポートします。

単位

PageWidthPageHeightLeftMarginTopMarginRightMarginBottomMargin値の用途への単位。

XResolutionYResolution解像度

ドキュメントファイルのラスタライズ時に使用する解像度。0の値は、現在の画面解像度(通常96)を使うつもりです。解像度は、結果として生じるラスター画像の画素密度を制御します。たとえば、96の8.5×11インチのページ幅と高さと解像度を指定するならば、結果として生じるimageは(8.5 * 96 = 816)と(11 * 96 = 1056)ピクセルのピクセル幅と高さを持っています。これは100パーセントのズームで表示するのに向いています、しかし、ズームインし始めるとき、imageはピクセル化されます。プリンターが通常モニターより非常に高い解像度を持っているため、プリンターにラスター画像を送るならば、ピクセル動作は発生もするかもしれません。

ズームインすることまたは高品質プリントがcodeの必要条件であるならば、より高い解像度値は指定されなければなりません(たとえば、300×300)。8.5×11インチのドキュメントのために、これは(8.5 * 300 = 2550)と(11 * 300 = 3300)ピクセルのラスター画像サイズに終わります。そして、それは、印刷するか、ズームインするのに十二分に向いています。解像度を増やすことが画像データを保持するのに用いられるメモリを増やすことを心にとめておきます。画素密度とメモリの消費の間の右釣合いを見つけることは、アプリケーションニーズに依存します。

SizeMode

物理的なラスター画像サイズにページ幅と高さで指定されている論理的サイズを変換するとき、変換が使ったコントロール。詳細については、「CodecsRasterizeDocumentSizeMode」を参照してください。

C#とVBは、CodecsRasterizeDocumentLoadOptionsの双方向実証のためにLEADTOOLSのバージョン付きで出荷するドキュメントデモをラスタライズしますを参照してください

サンプル
サンプルのために、参照しますCodecsPdfOptions

このサンプルは別にPDF文書をロードします。そして、ドキュメントオプションをラスタライズして、結果として生じるラスター画像幅のそのエフェクト、高さと解像度を示します。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

Public Sub RasterizeDocumentExample()
   ' Initialize the RasterCodecs object to use
   Dim codecs As New RasterCodecs()
   ' Enable using the RasterizeDocumentOptions
   Dim rasterizeDocumentLoadOptions As CodecsRasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load

   ' No margins (only used with RTF and TXT files)
   rasterizeDocumentLoadOptions.LeftMargin = 0
   rasterizeDocumentLoadOptions.TopMargin = 0
   rasterizeDocumentLoadOptions.RightMargin = 0
   rasterizeDocumentLoadOptions.BottomMargin = 0

   ' The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as well
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf")

   ' Show the file information
   Using imageInfo As CodecsImageInfo = codecs.GetInformation(imageFileName, True)
      Dim documentImageInfo As CodecsDocumentImageInfo = imageInfo.Document

      ' If this is a document file, show the document information
      If documentImageInfo.IsDocumentFile Then
         Console.WriteLine("Document file")
         Console.WriteLine("  Original size is: {0} by {1} {2}", _
            documentImageInfo.PageWidth, documentImageInfo.PageHeight, documentImageInfo.Unit)

         Console.WriteLine("  Using current rasterization, load size will be: {0} by {1} pixels at {2} by {3}", _
            imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution)
      Else
         ' Regular raster image, show the image information
         Console.WriteLine("Raster file")
         Console.WriteLine("  Original size is: {0} by {1} pixels at {2} by {3}", _
            imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution)
      End If
   End Using

   ' Example 1. Load at original document size at 300 DPI
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.None
   rasterizeDocumentLoadOptions.XResolution = 300
   rasterizeDocumentLoadOptions.YResolution = 300

   Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
      ShowResult(codecs, image)
   End Using

   ' Example 2. Fit the document at 640 by 480 pixels at 96 DPI keeping the aspect ratio
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit
   rasterizeDocumentLoadOptions.PageWidth = 640
   rasterizeDocumentLoadOptions.PageHeight = 480
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Pixel
   rasterizeDocumentLoadOptions.XResolution = 96
   rasterizeDocumentLoadOptions.YResolution = 96

   Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
      ShowResult(codecs, image)
   End Using

   ' Example 3. Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratio
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit
   rasterizeDocumentLoadOptions.PageWidth = 8.5
   rasterizeDocumentLoadOptions.PageHeight = 11
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch
   rasterizeDocumentLoadOptions.XResolution = 300
   rasterizeDocumentLoadOptions.YResolution = 300

   Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
      ShowResult(codecs, image)
   End Using

   ' Example 4. Stretch the image to always be 4 by 4 inches at 150 DPI. Aspect ratio may differ
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Stretch
   rasterizeDocumentLoadOptions.PageWidth = 4
   rasterizeDocumentLoadOptions.PageHeight = 4
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch
   rasterizeDocumentLoadOptions.XResolution = 150
   rasterizeDocumentLoadOptions.YResolution = 150

   Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
      ShowResult(codecs, image)
   End Using

   codecs.Dispose()
End Sub

Private Shared Sub ShowResult(ByVal codecs As RasterCodecs, ByVal image As RasterImage)
   Dim rasterizeDocumentLoadOptions As CodecsRasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load

   Console.WriteLine("Showing result..")
   Console.WriteLine("  Current rasterization options:")
   Console.WriteLine("    Size mode is: {0}", rasterizeDocumentLoadOptions.SizeMode)
   Console.WriteLine("    Page size is {0} by {1} {2}", _
      rasterizeDocumentLoadOptions.PageWidth, rasterizeDocumentLoadOptions.PageHeight, rasterizeDocumentLoadOptions.Unit)
   Console.WriteLine("    Resolution is {0} by {1}", _
      rasterizeDocumentLoadOptions.XResolution, rasterizeDocumentLoadOptions.YResolution)

   Console.WriteLine("  Loaded raster image size is: {0} by {1} at {2} by {3}", _
      image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution)

   ' Code to verify our results

   ' Get the suggested page width and height in pixels
   Dim pageWidthInPixels As Double
   Dim pageHeightInPixels As Double

   Select Case rasterizeDocumentLoadOptions.Unit
      Case CodecsRasterizeDocumentUnit.Inch
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution

      Case CodecsRasterizeDocumentUnit.Millimeter
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution * 25.400000025908
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution * 25.400000025908

      Case CodecsRasterizeDocumentUnit.Pixel
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight
   End Select

   ' Verify
   Select Case rasterizeDocumentLoadOptions.SizeMode
      Case CodecsRasterizeDocumentSizeMode.Fit, CodecsRasterizeDocumentSizeMode.FitAlways
         ' The image width/height must not be greater than suggested page width/height
         Console.WriteLine("Image width/height must be less than or equal to page width/height")
         System.Diagnostics.Debug.Assert(image.ImageWidth <= pageWidthInPixels)
         System.Diagnostics.Debug.Assert(image.ImageHeight <= pageHeightInPixels)

      Case CodecsRasterizeDocumentSizeMode.FitWidth
         ' The image width must be equal to the suggested page width
         Console.WriteLine("Image width must be equal to page width")
         System.Diagnostics.Debug.Assert(image.ImageWidth = pageWidthInPixels)

      Case CodecsRasterizeDocumentSizeMode.Stretch
         ' The image width/height must be equal to the suggested page width/height
         Console.WriteLine("Image width/height must be equal to suggested page width/height")
         System.Diagnostics.Debug.Assert(image.ImageWidth = pageWidthInPixels)
         System.Diagnostics.Debug.Assert(image.ImageHeight = pageHeightInPixels)

      Case CodecsRasterizeDocumentSizeMode.None
         Console.WriteLine("Loading at original document page size")
         ' No checking
   End Select
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;

public void RasterizeDocumentExample()
{
   // Initialize the RasterCodecs object to use
   RasterCodecs codecs = new RasterCodecs();
   // Enable using the RasterizeDocumentOptions
   CodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;

   // No margins (only used with RTF and TXT files)
   rasterizeDocumentLoadOptions.LeftMargin = 0;
   rasterizeDocumentLoadOptions.TopMargin = 0;
   rasterizeDocumentLoadOptions.RightMargin = 0;
   rasterizeDocumentLoadOptions.BottomMargin = 0;

   // The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as well
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf");

   // Show the file information
   using (CodecsImageInfo imageInfo = codecs.GetInformation(imageFileName, true))
   {
      CodecsDocumentImageInfo documentImageInfo = imageInfo.Document;

      // If this is a document file, show the document information
      if (documentImageInfo.IsDocumentFile)
      {
         Console.WriteLine("Document file");
         Console.WriteLine("  Original size is: {0} by {1} {2}",
            documentImageInfo.PageWidth, documentImageInfo.PageHeight, documentImageInfo.Unit);

         Console.WriteLine("  Using current rasterization, load size will be: {0} by {1} pixels at {2} by {3}",
            imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);
      }
      else
      {
         // Regular raster image, show the image information
         Console.WriteLine("Raster file");
         Console.WriteLine("  Original size is: {0} by {1} pixels at {2} by {3}",
            imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);
      }
   }

   // Example 1. Load at original document size at 300 DPI
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.None;
   rasterizeDocumentLoadOptions.XResolution = 300;
   rasterizeDocumentLoadOptions.YResolution = 300;

   using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
   {
      ShowResult(codecs, image);
   }

   // Example 2. Fit the document at 640 by 480 pixels at 96 DPI keeping the aspect ratio
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;
   rasterizeDocumentLoadOptions.PageWidth = 640;
   rasterizeDocumentLoadOptions.PageHeight = 480;
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Pixel;
   rasterizeDocumentLoadOptions.XResolution = 96;
   rasterizeDocumentLoadOptions.YResolution = 96;

   using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
   {
      ShowResult(codecs, image);
   }

   // Example 3. Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratio
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;
   rasterizeDocumentLoadOptions.PageWidth = 8.5;
   rasterizeDocumentLoadOptions.PageHeight = 11;
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;
   rasterizeDocumentLoadOptions.XResolution = 300;
   rasterizeDocumentLoadOptions.YResolution = 300;

   using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
   {
      ShowResult(codecs, image);
   }

   // Example 4. Stretch the image to always be 4 by 4 inches at 150 DPI. Aspect ratio may differ
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Stretch;
   rasterizeDocumentLoadOptions.PageWidth = 4;
   rasterizeDocumentLoadOptions.PageHeight = 4;
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;
   rasterizeDocumentLoadOptions.XResolution = 150;
   rasterizeDocumentLoadOptions.YResolution = 150;

   using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
   {
      ShowResult(codecs, image);
   }

   codecs.Dispose();
}

private static void ShowResult(RasterCodecs codecs, RasterImage image)
{
   CodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;

   Console.WriteLine("Showing result..");
   Console.WriteLine("  Current rasterization options:");
   Console.WriteLine("    Size mode is: {0}", rasterizeDocumentLoadOptions.SizeMode);
   Console.WriteLine("    Page size is {0} by {1} {2}",
      rasterizeDocumentLoadOptions.PageWidth, rasterizeDocumentLoadOptions.PageHeight, rasterizeDocumentLoadOptions.Unit);
   Console.WriteLine("    Resolution is {0} by {1}",
      rasterizeDocumentLoadOptions.XResolution, rasterizeDocumentLoadOptions.YResolution);

   Console.WriteLine("  Loaded raster image size is: {0} by {1} at {2} by {3}",
      image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);

   // Code to verify our results

   // Get the suggested page width and height in pixels
   double pageWidthInPixels;
   double pageHeightInPixels;

   switch (rasterizeDocumentLoadOptions.Unit)
   {
      case CodecsRasterizeDocumentUnit.Inch:
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution;
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution;
         break;

      case CodecsRasterizeDocumentUnit.Millimeter:
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution * 25.400000025908000026426160026955;
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution * 25.400000025908000026426160026955;
         break;

      case CodecsRasterizeDocumentUnit.Pixel:
      default:
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth;
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight;
         break;
   }

   // Verify
   switch (rasterizeDocumentLoadOptions.SizeMode)
   {
      case CodecsRasterizeDocumentSizeMode.Fit:
      case CodecsRasterizeDocumentSizeMode.FitAlways:
         // The image width/height must not be greater than suggested page width/height
         Console.WriteLine("Image width/height must be less than or equal to page width/height");
         System.Diagnostics.Debug.Assert(image.ImageWidth <= pageWidthInPixels);
         System.Diagnostics.Debug.Assert(image.ImageHeight <= pageHeightInPixels);
         break;

      case CodecsRasterizeDocumentSizeMode.FitWidth:
         // The image width must be equal to the suggested page width
         Console.WriteLine("Image width must be equal to page width");
         System.Diagnostics.Debug.Assert(image.ImageWidth == pageWidthInPixels);
         break;

      case CodecsRasterizeDocumentSizeMode.Stretch:
         // The image width/height must be equal to the suggested page width/height
         Console.WriteLine("Image width/height must be equal to suggested page width/height");
         System.Diagnostics.Debug.Assert(image.ImageWidth == pageWidthInPixels);
         System.Diagnostics.Debug.Assert(image.ImageHeight == pageHeightInPixels);
         break;

      case CodecsRasterizeDocumentSizeMode.None:
      default:
         Console.WriteLine("Loading at original document page size");
         // No checking
         break;
   }
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools;
using Leadtools.Codecs;

public async Task RasterizeDocumentExample()
{
   // Initialize the RasterCodecs object to use
   RasterCodecs codecs = new RasterCodecs();
   // Enable using the RasterizeDocumentOptions
   CodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;

   // No margins (only used with RTF and TXT files)
   rasterizeDocumentLoadOptions.LeftMargin = 0;
   rasterizeDocumentLoadOptions.TopMargin = 0;
   rasterizeDocumentLoadOptions.RightMargin = 0;
   rasterizeDocumentLoadOptions.BottomMargin = 0;

   // The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as well
   string srcFileName = @"Assets\Leadtools.pdf";

   // Show the file information
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), true, 1))
   {
      CodecsDocumentImageInfo documentImageInfo = imageInfo.Document;

      // If this is a document file, show the document information
      if (documentImageInfo.IsDocumentFile)
      {
         Debug.WriteLine("Document file");
         Debug.WriteLine("  Original size is: {0} by {1} {2}",
            documentImageInfo.PageWidth, documentImageInfo.PageHeight, documentImageInfo.Unit);

         Debug.WriteLine("  Using current rasterization, load size will be: {0} by {1} pixels at {2} by {3}",
            imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);
      }
      else
      {
         // Regular raster image, show the image information
         Debug.WriteLine("Raster file");
         Debug.WriteLine("  Original size is: {0} by {1} pixels at {2} by {3}",
            imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);
      }
   }

   // Example 1. Load at original document size at 300 DPI
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.None;
   rasterizeDocumentLoadOptions.XResolution = 300;
   rasterizeDocumentLoadOptions.YResolution = 300;

   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.Bgr, 1, 1))
   {
      ShowResult(codecs, srcImage);
   }

   // Example 2. Fit the document at 640 by 480 pixels at 96 DPI keeping the aspect ratio
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;
   rasterizeDocumentLoadOptions.PageWidth = 640;
   rasterizeDocumentLoadOptions.PageHeight = 480;
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Pixel;
   rasterizeDocumentLoadOptions.XResolution = 96;
   rasterizeDocumentLoadOptions.YResolution = 96;

   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.Bgr, 1, 1))
   {
      ShowResult(codecs, srcImage);
   }

   // Example 3. Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratio
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;
   rasterizeDocumentLoadOptions.PageWidth = 8.5;
   rasterizeDocumentLoadOptions.PageHeight = 11;
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;
   rasterizeDocumentLoadOptions.XResolution = 300;
   rasterizeDocumentLoadOptions.YResolution = 300;

   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.Bgr, 1, 1))
   {
      ShowResult(codecs, srcImage);
   }

   // Example 4. Stretch the image to always be 4 by 4 inches at 150 DPI. Aspect ratio may differ
   rasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Stretch;
   rasterizeDocumentLoadOptions.PageWidth = 4;
   rasterizeDocumentLoadOptions.PageHeight = 4;
   rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;
   rasterizeDocumentLoadOptions.XResolution = 150;
   rasterizeDocumentLoadOptions.YResolution = 150;

   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.Bgr, 1, 1))
   {
      ShowResult(codecs, srcImage);
   }

   codecs.Dispose();
}

private static void ShowResult(RasterCodecs codecs, RasterImage image)
{
   CodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;

   Debug.WriteLine("Showing result..");
   Debug.WriteLine("  Current rasterization options:");
   Debug.WriteLine("    Size mode is: {0}", rasterizeDocumentLoadOptions.SizeMode);
   Debug.WriteLine("    Page size is {0} by {1} {2}",
      rasterizeDocumentLoadOptions.PageWidth, rasterizeDocumentLoadOptions.PageHeight, rasterizeDocumentLoadOptions.Unit);
   Debug.WriteLine("    Resolution is {0} by {1}",
      rasterizeDocumentLoadOptions.XResolution, rasterizeDocumentLoadOptions.YResolution);

   Debug.WriteLine("  Loaded raster image size is: {0} by {1} at {2} by {3}",
      image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);

   // Code to verify our results

   // Get the suggested page width and height in pixels
   double pageWidthInPixels;
   double pageHeightInPixels;

   switch (rasterizeDocumentLoadOptions.Unit)
   {
      case CodecsRasterizeDocumentUnit.Inch:
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution;
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution;
         break;

      case CodecsRasterizeDocumentUnit.Millimeter:
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution * 25.400000025908000026426160026955;
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution * 25.400000025908000026426160026955;
         break;

      case CodecsRasterizeDocumentUnit.Pixel:
      default:
         pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth;
         pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight;
         break;
   }

   // Verify
   switch (rasterizeDocumentLoadOptions.SizeMode)
   {
      case CodecsRasterizeDocumentSizeMode.Fit:
      case CodecsRasterizeDocumentSizeMode.FitAlways:
         // The image width/height must not be greater than suggested page width/height
         Debug.WriteLine("Image width/height must be less than or equal to page width/height");
         Assert.IsTrue(image.ImageWidth <= pageWidthInPixels);
         Assert.IsTrue(image.ImageHeight <= pageHeightInPixels);
         break;

      case CodecsRasterizeDocumentSizeMode.FitWidth:
         // The image width must be equal to the suggested page width
         Debug.WriteLine("Image width must be equal to page width");
         Assert.IsTrue(image.ImageWidth == pageWidthInPixels);
         break;

      case CodecsRasterizeDocumentSizeMode.Stretch:
         // The image width/height must be equal to the suggested page width/height
         Debug.WriteLine("Image width/height must be equal to suggested page width/height");
         Assert.IsTrue(image.ImageWidth == pageWidthInPixels);
         Assert.IsTrue(image.ImageHeight == pageHeightInPixels);
         break;

      case CodecsRasterizeDocumentSizeMode.None:
      default:
         Debug.WriteLine("Loading at original document page size");
         // No checking
         break;
   }
}
必要条件

ターゲットプラットホーム

参照

参照

CodecsRasterizeDocumentLoadOptionsメンバ
Leadtools.Codecs名前空間
PDF機能の実装
CodecsDocumentImageInfoクラス