Share via


IXpsOMObjectFactory::CreateImageResource 方法 (xpsobjectmodel.h)

建立 IXpsOMImageResource 介面,用來存取映像資源數據流。

語法

HRESULT CreateImageResource(
  [in]          IStream             *acquiredStream,
  [in]          XPS_IMAGE_TYPE      contentType,
  [in]          IOpcPartUri         *partUri,
  [out, retval] IXpsOMImageResource **imageResource
);

參數

[in] acquiredStream

要與此資源相關聯的唯讀數據流。 此參數不得為 NULL

重要 將此數據流視為 Single-Threaded Apartment (STA) 物件;請勿重新輸入。
 

[in] contentType

XPS_IMAGE_TYPE值,描述 acquiredStream 所參考之數據流的影像類型。

[in] partUri

包含要指派給此資源的元件名稱的 IOpcPartUri 介面。 此參數不得為 NULL

[out, retval] imageResource

IXpsOMImageResource 介面的指標。

傳回值

方法會傳回 HRESULT。 可能的值包括但不限於下列數據表中的值。 如需此表格中未列出的 XPS 檔 API 傳回值的相關信息,請參閱 XPS 檔錯誤

傳回碼 描述
S_OK
此方法已成功。
E_INVALIDARG
contentType 不是有效的 XPS_IMAGE_TYPE 值。
E_POINTER
acquiredStreampartUriimageResourceNULL

備註

下列程式代碼範例說明如何使用此方法來建立新的介面。


IXpsOMImageResource    *newInterface;
// The following values are defined outside of 
// this example.
//  IStream            *acquiredStream;
//  XPS_IMAGE_TYPE     contentType;
//  IOpcPartUri        *partUri;
    
// Note the implicit requirement that CoInitializeEx 
//  has previously been called from this thread.

hr = CoCreateInstance(
    __uuidof(XpsOMObjectFactory),
    NULL,
    CLSCTX_INPROC_SERVER,
    _uuidof(IXpsOMObjectFactory),
    reinterpret_cast<LPVOID*>(&xpsFactory)
    );

if (SUCCEEDED(hr))
{
    // The partUriString and acquiredStream variables 
    //   are defined outside of this example.
    hr = xpsFactory->CreatePartUri(partUriString, &partUri);
    if (SUCCEEDED(hr))
    {
        hr = xpsFactory->CreateImageResource (
            acquiredStream,
            contentType,
            partUri,
            &newInterface);
        if (SUCCEEDED(hr))
        {
            // use newInterface

            newInterface->Release();
        }
        partUri->Release();
    }
    xpsFactory->Release();
}
else
{
    // evaluate HRESULT error returned in hr
}

規格需求

需求
最低支援的用戶端 適用於 Windows Vista 的 Windows 7、Windows Vista SP2 和平臺更新 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2008 R2、Windows Server 2008 SP2 和 Platform Update for Windows Server 2008 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 xpsobjectmodel.h

另請參閱

IOpcPartUri

IXpsOMImageResource

IXpsOMObjectFactory

XML Paper Specification

XPS 檔案錯誤

XPS_IMAGE_TYPE