|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
Sujet : Bitmap [ Archives / Au secours ] (sebastienbro)
Informations & options pour cette discussion
mercredi 14 avril 2004 à 14:02:09 |
Bitmap

sebastienbro
|
Bonjour à tous ! Voilà, en fait, je cherche à enregistrer un bitmap à partir d'un HDC ! En fait ça n'est pas pour l'enregistrer mais pour le compresser! Voici donc mon code qui marche très bien, sauf à un endroit, à savoir la fonction GetDIBits. J'ai lu dans MSDN que pour que cette fonction réussise, il faut que le HBITMAP ne soit associé à aucun object : problème ! Comment faire pour désassocié ce HBITMAP ? Voici mon code : Code:
int WINAPI AddUserWithHDC(char *UserName, HDC hdc, int Width, int Height) {
HBITMAP hbmp; BITMAP bmp; PBITMAPINFO pbmi; PBITMAPINFOHEADER pbih; BITMAPFILEHEADER hdr; LPBYTE buffer = NULL; WORD cClrBits; HDC hdc2;
FILE *test;
LPBYTE bitmap = NULL; if ((UserName == NULL) || (hdc == NULL) || (hFile == NULL)) return INVALID_PARAM_OR_FILE_NOT_OPEN;
if ((Width != 64) || (Height != 64)) return INVALID_PARAM;
if (avatar_offset(UserName) > 0) return USER_ALREADY_EXISTS;
if (! (hbmp = CreateCompatibleBitmap(hdc, Width, Width))) return UNKNOW_ERROR;
if (! GetObject(hbmp, sizeof(BITMAP), &bmp)) {
DeleteObject(hbmp); return UNKNOW_ERROR;
}
hdc2 = CreateCompatibleDC(hdc);
DeleteDC(hdc); cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel); if (cClrBits == 1) cClrBits = 1; else if (cClrBits <= 4) cClrBits = 4; else if (cClrBits <= 8) cClrBits = 8; else if (cClrBits <= 16) cClrBits = 16; else if (cClrBits <= 24) cClrBits = 24; else cClrBits = 32; if (cClrBits != 24) pbmi = (PBITMAPINFO) malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1<< cClrBits));
else pbmi = (PBITMAPINFO) malloc(sizeof(BITMAPINFOHEADER));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbmi->bmiHeader.biWidth = bmp.bmWidth; pbmi->bmiHeader.biHeight = bmp.bmHeight; pbmi->bmiHeader.biPlanes = bmp.bmPlanes; pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel; pbmi->bmiHeader.biXPelsPerMeter = 0; pbmi->bmiHeader.biYPelsPerMeter = 0;
if (cClrBits < 24) pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
pbmi->bmiHeader.biCompression = BI_RGB;
/*pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 7) /8 * pbmi->bmiHeader.biHeight * cClrBits; */
GetDIBits(hdc2, hbmp, 0, 64, NULL, pbmi, DIB_RGB_COLORS);
pbmi->bmiHeader.biClrImportant = 0; pbmi->bmiHeader.biClrUsed = 0;
pbih = (PBITMAPINFOHEADER) pbmi; buffer = (LPBYTE) malloc(pbih->biSizeImage); if (! buffer) {
DeleteObject(hbmp); return UNKNOW_ERROR;
}
problème ici! if (! GetDIBits(hdc2, hbmp, 0, (WORD) pbih->biHeight, (void *)buffer, pbmi, DIB_RGB_COLORS))) { DeleteObject(hbmp); return UNKNOW_ERROR; }
hdr.bfType = 0x4d42; hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + (pbih->biClrUsed * sizeof(RGBQUAD)) + pbih->biSizeImage); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD);
bitmap = (LPBYTE) malloc(sizeof(BITMAPFILEHEADER) + (sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD)) + pbih->biSizeImage);
memcpy((void *)bitmap, (void *)&hdr, sizeof(BITMAPFILEHEADER));
memcpy((void *)(bitmap + sizeof(BITMAPFILEHEADER)), (void *) pbih, (sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof(RGBQUAD)) );
memcpy((void *)(bitmap + hdr.bfOffBits), (void *) buffer, pbih->biSizeImage);
free(buffer); free(bitmap);
DeleteObject(hbmp); return NO_ERROR;
}
| En fait, la fonction GetDIBits marche, mais elle retourne dans le buffer que des 0 et aucune image ! S'il vous plait aidez moi parceque j'ai essayé pas mal de chose mais rien y fait ! Merci d'avance ! Bye Seb \* -- Seb [ Mail] [ Web] -- */
|
|
|
mercredi 14 avril 2004 à 19:58:12 |
Re : Bitmap

ymca2003
|
ton pb vient de la récupération du HBITMAP : if (! (hbmp = CreateCompatibleBitmap(hdc, Width, Width))) return UNKNOW_ERROR;
ca ce fait que créer un bitmap vide.
ce qu'il fauf faire : HDC hBmpDC = CreateCompatibleDC(hdc); HBITMAP hBmp = CreateCompatibleBitmap(hdc, width, height); HBITMP hOldBmp = SelectObject(hMemDC, hBmp); BitBlt(hBmpDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY); SelectObject(hBmpDC, hOldBmp); DeleteDC(hBmpDC);
|
|
|
mercredi 14 avril 2004 à 21:38:38 |
Re : Bitmap

sebastienbro
|
Oh merci beaucoup !!! Ca marche maintenant ! Je croyait à tord que CreateCompatibleBitmap créait un bitmap qui correspondait au bitmap qui était sur le HDC ! Merci encore ! Bye \* -- Seb [ Mail] [ Web] -- */
|
|
|
Cette discussion est classé dans : bmiheader, bitmap, pbmi, pbih, sizeof
Répondre à ce message
Sujets en rapport avec ce message
Récupération des pixels d'une fenêtre cachée [ par sebcmoa ]
Bonjour, Je vous expose mon problème : - J'utilise la fonction glReadPixels sur une fenêtre invisible. Cela me retourne bien les données...mais problè
Problem d'envoi de fichier par socket en c [ par dyroj ]
Bonjour, je veut envoyer un fichier(image, texte, executable) via les socket en c, j'ai créer mon programme et il marche que pour les fichier texte. P
Technologie et type de format renvoyé par une webcam [ par Evanok ]
Bonjour, Je dois réaliser un projet me permettant de mouvoir le curseur de ma souris grace a un mouvement détecté devant ma webcam. Je suis en train d
Programme C C++ , Création et affichage d'une bitmap [ par ben349 ]
Bonjour, je suis débutant en programmation C C++, j'ai fait un petit programme en application console qui crée et affiche une bitmap en m'aidant un pe
sizeof(int *) // ca doit marché MAIS [ par amine1234Z ]
Bonjour void Somme(int* entierConverti1,int* entierConverti2){int nbr_case_str1=sizeof(*entierConverti1)+1;int nbr_case_str2=<font color="
Modifier le chemin d'un bitmap. [ par linuxfr ]
Bonjour,Je crée une application dans lequel je choisis une image qui s'affiche ensuite dans un bouton (CBitmapButton).Je souhaiterais en fait, affiche
erreur 500 bad syntax pour envoi de mail pas le protocole smtp [ par dyroj ]
bonjour,je narrive pas a envoyer les requetre smtp au serveur smtp.free.fr,jarrive a me connecter sans problem,mais quand jenvoi une requette, je reco
squelette d'une image bitmap en c++ [ par dadou846 ]
salut à tous,j'ai une image bitmap en niveau de gris et je souhaite extraire le squelette.j'utilise Visual Basic C++ 6.0 svp si quelqu'un possède un b
squelette d'une image bitmap avec opencv [ par dadou846 ]
salut,svp j'ai besoin de réaliser une squelettisation d'une image en niveau de gris, j'ai trop charché un bout de code en c++ mais j'ai pas trouvé, j'
Livres en rapport
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|