J'ai un code de travail qui utilise IImgCtx pour charger des images, mais je n'arrive pas à trouver comment obtenir le canal alpha. Pour les images comme .gif et .png, il y a des pixels transparents, mais l'utilisation de n'importe quel autre bitmap 24 bits comme surface de dessin ne fonctionne pas.Comment utiliser IImgCtx pour charger une image avec un canal alpha?
Pour référence sur l'interface: http://www.codeproject.com/KB/graphics/JianImgCtxDecoder.aspx
Mon code ressemble à ceci:
IImgCtx *Ctx = 0;
HRESULT hr = CoCreateInstance(CLSID_IImgCtx, NULL, CLSCTX_INPROC_SERVER, IID_IImgCtx, (LPVOID*)&Ctx);
if (SUCCEEDED(hr))
{
GVariant Fn = Name;
hr = Ctx->Load(Fn.WStr(), 0);
if (SUCCEEDED(hr))
{
SIZE Size = { -1, -1 };
ULONG State = 0;
while (true)
{
hr = Ctx->GetStateInfo(&State, &Size, false);
if (SUCCEEDED(hr))
{
if ((State & IMGLOAD_COMPLETE) || (State & IMGLOAD_STOPPED) || (State & IMGLOAD_ERROR))
{
break;
}
else
{
Sleep(1);
}
}
else break;
}
if (Size.cx > 0 &&
Size.cy > 0 &&
pDC.Reset(new GMemDC))
{
if (pDC->Create(Size.cx, Size.cy, 32))
{
HDC hDC = pDC->StartDC();
if (hDC)
{
RECT rc = { 0, 0, pDC->X(), pDC->Y() };
Ctx->Draw(hDC, &rc);
pDC->EndDC();
}
}
else pDC.Reset();
}
}
Ctx->Release();
Où "StartDC" enveloppe essentiellement CreateCompatibleDC (NULL) et "EndDC" encapsule DeleteDC, avec SelectObjects appropriés pour HBITMAPS etc. Et pDC-> Create (x, y, bit_depth) appelle CreateDIBSection (... DIB_RGB_COLORS ...). Donc, cela fonctionne si je crée un bitmap 24 bits/pixel, mais n'a pas d'alpha pour parler, et si je passe un bitmap 32 bits/pixel, il remplit les canaux de couleur RVB et laisse le canal alpha 0x00. Si je OU le canal alpha avec 0xff pour rendre l'image complètement opaque, il ressemble à l'option 24 bpp. Maintenant, cette interface est apparemment utilisée par Internet Explorer pour charger des images, et évidemment, cela supporte la transparence, donc je crois qu'il est possible d'obtenir un certain niveau d'alpha sur l'interface. La question est comment?
(j'ai aussi tomber le code de retour qui appellera libpng/libjpeg/mon chargeur .gif etc)