IWICColorTransform::Initialize 方法 (wincodec.h)
使用IWICBitmapSource初始化IWICColorTransform,並將它從一個IWICColorCoNtext轉換成另一個。
語法
HRESULT Initialize(
[in] IWICBitmapSource *pIBitmapSource,
[in] IWICColorContext *pIContextSource,
[in] IWICColorContext *pIContextDest,
[in] REFWICPixelFormatGUID pixelFmtDest
);
參數
[in] pIBitmapSource
類型: IWICBitmapSource*
用來初始化色彩轉換的點陣圖來源。
[in] pIContextSource
類型: IWICColorCoNtext*
色彩內容來源。
[in] pIContextDest
類型: IWICColorCoNtext*
色彩內容目的地。
[in] pixelFmtDest
類型: REFWICPixelFormatGUID
所需像素格式的 GUID。
此參數僅限於原生 WIC 像素格式的子集,請參閱清單的。
傳回值
類型: HRESULT
如果此方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。
備註
pICoNtextSource和pixelFmtDest參數目前支援的格式如下:
- GUID_WICPixelFormat8bppGray
- GUID_WICPixelFormat16bppGray
- GUID_WICPixelFormat16bppBGR555
- GUID_WICPixelFormat16bppBGR565
- GUID_WICPixelFormat24bppBGR
- GUID_WICPixelFormat24bppRGB
- GUID_WICPixelFormat32bppBGR
- GUID_WICPixelFormat32bppBGRA
- GUID_WICPixelFormat32bppPBGRA
- GUID_WICPixelFormat32bppPRGBA (Windows 8 和更新版本)
- GUID_WICPixelFormat32bppRGBA
- GUID_WICPixelFormat32bppBGR101010
- GUID_WICPixelFormat32bppCMYK
- GUID_WICPixelFormat48bppBGR
- GUID_WICPixelFormat64bppBGRA (Windows 8 和更新版本)
- GUID_WICPixelFormat64bppPBGRA (Windows 8 和更新版本)
- GUID_WICPixelFormat64bppPRGBA (Windows 8 和更新版本)
- GUID_WICPixelFormat64bppRGBA (Windows 8 和更新版本)
範例
下列範例會執行從一個 IWICColorCoNtext 到另一個的色彩轉換。
IWICImagingFactory *pFactory = NULL;
IWICBitmapDecoder *pDecoder = NULL;
IWICBitmapFrameDecode *pBitmapFrame = NULL;
IWICColorContext *pContextSrc = NULL;
IWICColorContext *pContextDst = NULL;
IWICColorTransform *pColorTransform = NULL;
UINT uiFrameCount = 0;
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL, CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*) &pFactory);
if (SUCCEEDED(hr))
{
hr = pFactory->CreateDecoderFromFilename(
L"test.jpg",
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnDemand,
&pDecoder);
}
if (SUCCEEDED(hr))
{
hr = pDecoder->GetFrameCount(&uiFrameCount);
}
if (SUCCEEDED(hr) && (uiFrameCount > 0))
{
hr = pDecoder->GetFrame(0, &piBitmapFrame);
}
if (SUCCEEDED(hr))
{
hr = pFactory->CreateColorContext(&pContextSrc);
}
if (SUCCEEDED(hr))
{
hr = pContextSrc->InitializeFromFilename(
L"c:\\windows\\system32\\spool\\drivers\\color\\kodak_dc.icm");
}
if (SUCCEEDED(hr))
{
hr = pFactory->CreateColorContext(&pContextDst);
}
if (SUCCEEDED(hr))
{
hr = pContextDst->InitializeFromFilename(
L"c:\\windows\\system32\\spool\\drivers\\color\\sRGB Color Space Profile.icm");
}
hr = E_FAIL;
if (SUCCEEDED(hr))
{
// Transform from src icm to the destination icm.
hr = pColorTransform->Initialize( pBitmapFrame,
pContextSrc,
pContextDst,
GUID_WICPixelFormat32bppBGRA);
}
if (SUCCEEDED(hr))
{
UINT uiWidth = 0, uiHeight = 0;
UINT cbStride = 0;
UINT cbBufferSize = 0;
BYTE *pbBuffer = NULL;
hr = pColorTransform->GetSize(&uiWidth, &uiHeight);
if (SUCCEEDED(hr))
{
WICRect rc = { 0 };
rc.X = 0;
rc.Y = 0;
rc.Width = uiWidth;
rc.Height = 1; // scanline
for (UINT i = 0; SUCCEEDED(hr) && (i < uiHeight); i++)
{
hr = pColorTransform->CopyPixels(&rc, cbStride, cbBufferSize - (rc.Y * cbStride), pbBuffer);
pbBuffer += cbStride;
rc.Y += 1;
}
}
}
if (pFactory)
{
pFactory->Release();
}
if (pDecoder)
{
pDecoder->Release();
}
if (pBitmapFrame)
{
pBitmapFrame->Release();
}
if (pContextSrc)
{
pContextSrc->Release();
}
if (pContextDst)
{
pContextDst->Release();
}
if (pColorTransform)
{
pColorTransform->Release();
}
return hr;
規格需求
最低支援的用戶端 | Windows XP 搭配 SP2、Windows Vista [傳統型應用程式 |UWP 應用程式] |
最低支援的伺服器 | Windows Server 2008 [傳統型應用程式 |UWP 應用程式] |
目標平台 | Windows |
標頭 | wincodec.h |
程式庫 | Windowscodecs.lib |
Dll | Windowscodecs.dll |