Méthode IWICColorTransform::Initialize (wincodec.h)
Initialise un IWICColorTransform avec un IWICBitmapSource et le transforme d’un IWICColorContext à un autre.
Syntaxe
HRESULT Initialize(
[in] IWICBitmapSource *pIBitmapSource,
[in] IWICColorContext *pIContextSource,
[in] IWICColorContext *pIContextDest,
[in] REFWICPixelFormatGUID pixelFmtDest
);
Paramètres
[in] pIBitmapSource
Type : IWICBitmapSource*
Source bitmap utilisée pour initialiser la transformation de couleur.
[in] pIContextSource
Type : IWICColorContext*
Source du contexte de couleur.
[in] pIContextDest
Type : IWICColorContext*
Destination du contexte de couleur.
[in] pixelFmtDest
Type : REFWICPixelFormatGUID
GUID du format de pixel souhaité.
Ce paramètre est limité à un sous-ensemble des formats de pixels WIC natifs. Consultez remarques pour une liste.
Valeur retournée
Type : HRESULT
Si cette méthode réussit, elle retourne S_OK. Sinon, elle retourne un code d’erreur HRESULT.
Remarques
Les formats actuellement pris en charge pour les paramètres pIContextSource et pixelFmtDest sont les suivants :
- GUID_WICPixelFormat8bppGray
- GUID_WICPixelFormat16bppGray
- GUID_WICPixelFormat16bppBGR555
- GUID_WICPixelFormat16bppBGR565
- GUID_WICPixelFormat24bppBGR
- GUID_WICPixelFormat24bppRGB
- GUID_WICPixelFormat32bppBGR
- GUID_WICPixelFormat32bppBGRA
- GUID_WICPixelFormat32bppPBGRA
- GUID_WICPixelFormat32bppPRGBA (Windows 8 et versions ultérieures)
- GUID_WICPixelFormat32bppRGBA
- GUID_WICPixelFormat32bppBGR101010
- GUID_WICPixelFormat32bppCMYK
- GUID_WICPixelFormat48bppBGR
- GUID_WICPixelFormat64bppBGRA (Windows 8 et versions ultérieures)
- GUID_WICPixelFormat64bppPBGRA (Windows 8 et versions ultérieures)
- GUID_WICPixelFormat64bppPRGBA (Windows 8 et versions ultérieures)
- GUID_WICPixelFormat64bppRGBA (Windows 8 et versions ultérieures)
Exemples
L’exemple suivant effectue une transformation de couleur d’un IWICColorContext à un autre.
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;
Configuration requise
Client minimal pris en charge | Windows XP avec SP2, Windows Vista [applications de bureau | Applications UWP] |
Serveur minimal pris en charge | Windows Server 2008 [applications de bureau | applications UWP] |
Plateforme cible | Windows |
En-tête | wincodec.h |
Bibliothèque | Windowscodecs.lib |
DLL | Windowscodecs.dll |
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour