En tant que sujet. Préférentiellement en utilisant le code C.Comment détecter par programme si un bitmap a un canal alpha?
2
A
Répondre
1
Avec :: GetDIBits comme décrit #333559
1
Sur cette réponse on ne sait pas quoi faire avec GetDIBits():
GetDIBits (hdc, hBmp, 0, 1, (void **) & bits, & bmi, DIB_RGB_COLORS);
bits [3] == alpha du pixel supérieur;
Les bits [3] doivent-ils être testés contre zéro? que faire avec cette valeur? merci,
1
J'ai implémenté un prototype mais ça ne fonctionne pas bien, donc il y a peut-être quelque chose qui ne va pas dans le code. Je partage ici avec l'espoir que nous pouvons le réparer ensemble:
BOOL HasAlphaChannel(HBITMAP hBmp)
{
HDC hDC = CreateCompatibleDC(NULL);
BITMAPINFO bmi;
void * bits;
unsigned long ul;
BOOL bAlphaChannel = FALSE;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
GetDIBits(hDC, hBmp, 0, 1, NULL, &bmi, DIB_RGB_COLORS);
bits = malloc(bmi.bmiHeader.biSizeImage);
// this is returning zero wich means error (why???)
GetDIBits(hDC, hBmp, 0, bmi.bmiHeader.biHeight, &bits, &bmi, DIB_RGB_COLORS);
for(ul = 0; ul < bmi.bmiHeader.biSizeImage; ul += 4)
if(((char *) bits)[ ul + 3 ] != 0)
bAlphaChannel = TRUE;
free(bits);
DeleteDC(hDC);
return bAlphaChannel;
}
Merci!
3
========= MFC++ version
private: static Boolean __gc* BitmapHasAlpha(BitmapData __gc* bmpData)
{
if ((bmpData->PixelFormat != PixelFormat::Format32bppArgb) && (bmpData->PixelFormat != PixelFormat::Format32bppRgb))
{
return false;
}
for (Int32 __gc* i = 0; (i < bmpData->Height); i++)
{
Int32 __gc* num2 = (i * bmpData->Stride);
for (Int32 __gc* j = 3; (j < (bmpData->Width * 4)); j += 4)
{
Byte __gc** numPtr = *static_cast<__box Byte __gc***>(((bmpData->Scan0->ToPointer() + num2) + j));
if (numPtr[0] != 0)
{
return true;
}
}
}
return false;
}
========= C# Version
private static unsafe bool BitmapHasAlpha(BitmapData bmpData)
{
if ((bmpData.PixelFormat != PixelFormat.Format32bppArgb) && (bmpData.PixelFormat != PixelFormat.Format32bppRgb))
{
return false;
}
for (int i = 0; i < bmpData.Height; i++)
{
int num2 = i * bmpData.Stride;
for (int j = 3; j < (bmpData.Width * 4); j += 4)
{
byte* numPtr = ((byte*)bmpData.Scan0.ToPointer()) + num2 + j;
if (numPtr[0] != 0)
{
return true;
}
}
}
return false;
}
0
Utilisez GetDIBits (hdc, hbmp, 0, 1, NULL, & bmi, DIB_RGB_COLORS).
Et puis voir si bmi.bmiHeader.biBitCount a une valeur de 32 alors il a canal alpha, sinon il n'a pas alpha.
Questions connexes
- 1. Comment créer un bitmap avec un canal alpha à la volée en utilisant GDI?
- 2. Comment puis-je dessiner une image avec un canal alpha défini par programme dans .NET?
- 3. Canal alpha dans OpenCV
- 4. Comment détecter si un événement onscroll a été généré par programme?
- 5. redimensionnement d'une image avec canal alpha
- 6. Effacer le canal alpha d'un NSImage
- 7. Comment obtenir une vignette de dossier avec canal alpha
- 8. Représentation hexadécimale d'une couleur avec un canal alpha?
- 9. Comment détecter si un graphique sera tramé?
- 10. Comment puis-je savoir si une autre application a enregistré un canal IPC Remoting?
- 11. canal Alpha dans IE 6.x
- 12. Inscriber Technology Via Builder et Delphi - Support du canal Alpha
- 13. Comment dessiner un bitmap avec 50% d'opacité?
- 14. Détecter si un formulaire a été soumis avec PHP
- 15. Comment dessiner un bitmap ARGB en utilisant GDI +?
- 16. Détecter si l'application Access a une erreur
- 17. Comment détecter si un moniteur est grand écran sous Windows
- 18. Comment détecter si un nombre donné est un nombre entier?
- 19. Comment détecter si un moniteur est en mode veille?
- 20. Comment détecter si un lecteur spécifique est un disque dur?
- 21. Détecter en C si sortie vers un terminal
- 22. Comment déterminer par programme si un contrôle ActiveX a été installé et si celui-ci ou ActiveX dans son ensemble a été désactivé?
- 23. Détecter si un noeud Gtk.TreeNode est développé
- 24. Comment puis-je détecter par programme ASP.NET 3.5?
- 25. Comment détecter si mon programme fonctionne sous Windows?
- 26. Comment puis-je savoir si un SPWeb donné est un site SearchCenter par programme
- 27. Comment vérifier si un assemblage a changé
- 28. comment détecter si VBA excel a trouvé quelque chose?
- 29. comment détecter si une URL pointe vers un fichier SWF
- 30. Comment programmer un routeur par programme?
Si vous utilisez des bits [3], il s'agit probablement d'un bitmap 24 bits avec BGR [B] GR, donc vous obtiendrez une valeur bleue, pas alpha. – dns