フレームを表示

L_SetRasterizeDocOptions

フレームを表示

#include "l_bitmap.h"

L_LTFIL_API L_INT EXT_FUNCTION L_SetRasterizeDocOptionspRasterizeDocOptions

pRASTERIZEDOCOPTIONS pRasterizeDocOptions;

/* 構造体へのポインタ*/

文書ファイルをラスタライズするとき、LEADTOOLSにより用いられるファイルオプションを設定します。

パラメーター

説明

pRasterizeDocOptions

文書ファイルをラスタライズするとき、使われるオプションを格納する構造体へのポインタ。

戻り値

SUCCESS

関数は成功しました。

<1

エラーが発生しました。リターンコードを参照してください

コメント

この関数によって設定される値は、現在のスレッドに有効です。現在のスレッドにより用いられる値を変更するために、この関数は、再び呼び出されなければなりません。

文書ファイルをラスタライズするとき、使われる現在のオプションを取得するために、L_GetRasterizeDocOptionsを呼び出します。

必須のDLLとライブラリ

LTFIL
ファイルフォーマットDLL

ツールキットバージョンに基づいた正確なDLLとライブラリのリストについては、「アプリケーションとともに配布するファイル」を参照してください

プラットホーム

Win32、x64、Linux

参照

関数:

L_GetRasterizeDocOptions

トピック:

ラスター画像は機能します:ファイルのロード

 

イメージのロードと保存

サンプル

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

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


static const L_CHAR* GetUnitName(RASTERIZEDOC_UNIT uUnit)
{
   switch(uUnit)
   {
      case RASTERIZEDOC_UNIT_PIXEL: return "Pixel";
      case RASTERIZEDOC_UNIT_INCH: return "Inch";
      case RASTERIZEDOC_UNIT_MILLIMETER: "Millimeter";
      default: return "";
   }
}

static L_VOID ShowResult(BITMAPHANDLE* pBitmap)
{
   RASTERIZEDOCOPTIONS rasterizeDocOptions;
   L_DOUBLE pageWidthInPixels;
   L_DOUBLE pageHeightInPixels;

   ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
   L_GetRasterizeDocOptions(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));

   printf("Showing result..\n");
   printf("  Current rasterization options:\n");

   printf("    Size mode is: ");
   switch(rasterizeDocOptions.uSizeMode)
   {
      case RASTERIZEDOC_SIZEMODE_NONE: printf("None\n"); break;
      case RASTERIZEDOC_SIZEMODE_FIT: printf("Fit\n"); break;
      case RASTERIZEDOC_SIZEMODE_FIT_ALWAYS: printf("Fit always\n"); break;
      case RASTERIZEDOC_SIZEMODE_FIT_WIDTH: printf("Fit width\n"); break;
      case RASTERIZEDOC_SIZEMODE_STRETCH: printf("Stretch\n"); break;
   }

   printf("    Page size is %.3f by %.3f %s\n",
      rasterizeDocOptions.dPageWidth, rasterizeDocOptions.dPageHeight, GetUnitName(rasterizeDocOptions.uUnit));
   printf("    Resolution is %u by %u\n",
      rasterizeDocOptions.uXResolution, rasterizeDocOptions.uYResolution);

   printf("  Loaded raster image size is: %u by %u at %u by %u\n",
      BITMAPWIDTH(pBitmap), BITMAPHEIGHT(pBitmap), pBitmap->XResolution, pBitmap->YResolution);

   // Code to verify our results

   // Get the suggested page width and height in pixels
   switch(rasterizeDocOptions.uUnit)
   {
      case RASTERIZEDOC_UNIT_INCH:
         pageWidthInPixels = rasterizeDocOptions.dPageWidth * rasterizeDocOptions.uXResolution;
         pageHeightInPixels = rasterizeDocOptions.dPageHeight * rasterizeDocOptions.uYResolution;
         break;

      case RASTERIZEDOC_UNIT_MILLIMETER:
         pageWidthInPixels = rasterizeDocOptions.dPageWidth * rasterizeDocOptions.uXResolution * 25.400000025908000026426160026955;
         pageHeightInPixels = rasterizeDocOptions.dPageHeight * rasterizeDocOptions.uYResolution * 25.400000025908000026426160026955;
         break;

      case RASTERIZEDOC_UNIT_PIXEL:
      default:
         pageWidthInPixels = rasterizeDocOptions.dPageWidth;
         pageHeightInPixels = rasterizeDocOptions.dPageHeight;
         break;
   }

   // Verify
   switch(rasterizeDocOptions.uSizeMode)
   {
      case RASTERIZEDOC_SIZEMODE_FIT:
      case RASTERIZEDOC_SIZEMODE_FIT_ALWAYS:
         // The image width/height must not be greater than suggested page width/height
         printf("Image width/height must be less than or equal to page width/height\n");
         assert(BITMAPWIDTH(pBitmap) <= pageWidthInPixels);
         assert(BITMAPHEIGHT(pBitmap) <= pageHeightInPixels);
         break;

      case RASTERIZEDOC_SIZEMODE_FIT_WIDTH:
         // The image width must be equal to the suggested page width
         printf("Image width must be equal to page width\n");
         assert(BITMAPWIDTH(pBitmap) == pageWidthInPixels);
         break;

      case RASTERIZEDOC_SIZEMODE_STRETCH:
         // The image width/height must be equal to the suggested page width/height
         printf("Image width/height must be equal to suggested page width/height\n");
         assert(BITMAPWIDTH(pBitmap) == pageWidthInPixels);
         assert(BITMAPHEIGHT(pBitmap) == pageHeightInPixels);
         break;

      case RASTERIZEDOC_SIZEMODE_NONE:
      default:
         printf("Loading at original document page size");
         // No checking
         break;
   }
}

L_LTFILTEX_API  L_INT RasterizeDocumentExample()
{
   // The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as well
   L_TCHAR* pszImageFileName = MAKE_IMAGE_PATH(TEXT("Leadtools.pdf"));
   RASTERIZEDOCOPTIONS rasterizeDocOptions;
   FILEINFO fileInfo;
   BITMAPHANDLE bitmap;
   L_INT nRet = 0;

   ZeroMemory(&fileInfo, sizeof(FILEINFO));
   ZeroMemory(&bitmap, sizeof(BITMAPHANDLE));

   // Enable using the RASTERIZEDOCOPTIONS
   ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
   nRet = L_GetRasterizeDocOptions(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
   if(nRet != SUCCESS)
      return nRet;

   // No margins (only used with RTF and TXT files)
   rasterizeDocOptions.dLeftMargin = 0;
   rasterizeDocOptions.dTopMargin = 0;
   rasterizeDocOptions.dRightMargin = 0;
   rasterizeDocOptions.dBottomMargin = 0;
   nRet =  L_SetRasterizeDocOptions(&rasterizeDocOptions);
   if(nRet != SUCCESS)
      return nRet;

   // Show the file information
   nRet = L_FileInfo(pszImageFileName, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL);
   if(nRet != SUCCESS)
      return nRet;

   // If this is a document file, show the document information
   if(fileInfo.bIsDocFile)
   {
      printf("Document file\n");
      printf("  Original size is: %.3f by %.3f %s\n",
         fileInfo.dDocPageWidth, fileInfo.dDocPageHeight, GetUnitName(fileInfo.uDocUnit));

      printf("  Using current rasterization, load size will be: %u by %u pixels at %u by %u\n",
         fileInfo.Width, fileInfo.Height, fileInfo.XResolution, fileInfo.YResolution);
   }
   else
   {
      // Regular raster image, show the image information
      printf("Raster file\n");
      printf("  Original size is: %u by %u pixels at %u by %u\n",
         fileInfo.Width, fileInfo.Height, fileInfo.XResolution, fileInfo.YResolution);
   }

   // Example 1. Load at original document size at 300 DPI
   rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_NONE;
   rasterizeDocOptions.uXResolution = 300;
   rasterizeDocOptions.uYResolution = 300;
   nRet = L_SetRasterizeDocOptions(&rasterizeDocOptions);
   if(nRet != SUCCESS)
      return nRet;

   nRet = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&bitmap);

   // Example 2. Fit the document at 640 by 480 pixels at 96 DPI keeping the aspect ratio
   rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_FIT;
   rasterizeDocOptions.dPageWidth = 640;
   rasterizeDocOptions.dPageHeight = 480;
   rasterizeDocOptions.uUnit = RASTERIZEDOC_UNIT_PIXEL;
   rasterizeDocOptions.uXResolution = 96;
   rasterizeDocOptions.uYResolution = 96;

   nRet = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&bitmap);

   // Example 3. Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratio
   rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_FIT;
   rasterizeDocOptions.dPageWidth = 8.5;
   rasterizeDocOptions.dPageHeight = 11;
   rasterizeDocOptions.uUnit = RASTERIZEDOC_UNIT_INCH;
   rasterizeDocOptions.uXResolution = 300;
   rasterizeDocOptions.uYResolution = 300;

   nRet = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&bitmap);

   // Example 4. Stretch the image to always be 4 by 4 inches at 150 DPI. Aspect ratio may differ
   rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_STRETCH;
   rasterizeDocOptions.dPageWidth = 4;
   rasterizeDocOptions.dPageHeight = 4;
   rasterizeDocOptions.uUnit = RASTERIZEDOC_UNIT_INCH;
   rasterizeDocOptions.uXResolution = 150;
   rasterizeDocOptions.uYResolution = 150;

   nRet = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&bitmap);

   return SUCCESS;
}