Mon image s'efface!!!

cs_tdeco Messages postés 53 Date d'inscription dimanche 23 février 2003 Statut Membre Dernière intervention 27 mai 2005 - 2 janv. 2005 à 05:31
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 - 5 janv. 2005 à 16:15
Bonjour
En fait, j'ai une boite de dialogue avec plusieurs boutons et une zone ou j'affiche une image bmp. Pour afficher l'image, je procède par la façon suivante:
HWND hBouton = GetDlgItem(hDlg_IHM_MAIN, IDC_IMAGE);
HDC hdc = GetDC(hBouton);
Dessiner_Image(hDlg_IHM_MAIN,hdc,&buffer);
ReleaseDC(hDlg_IHM_MAIN,hdc);

hDlg_IHM_MAIN est ma boite de dialogue principale,
IDC_IMAGE l'identifiant de ma zone d'affichage
Dans la fonction "Dessiner_Image" , j'utilise StretchBlt pour dessiner l'image dans le buffer.

Mon image s'affiche bien. J'appuis sur un bouton de l'IHM, je crée alors une autre boite de dialogue. Lorsque je ferme celle-ci , mon image s'est effacé

Quelqu'un peut il m'aider

Merci d'avance

5 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
2 janv. 2005 à 11:16
BM_SETIMAGE

ciao...
BruNews, MVP VC++
0
cs_tdeco Messages postés 53 Date d'inscription dimanche 23 février 2003 Statut Membre Dernière intervention 27 mai 2005
2 janv. 2005 à 16:26
Qu'est ce ke tu entends par là?
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
2 janv. 2005 à 16:36
Regarde BM_SETIMAGE dans MSDN ou recherche forum tu auras aussi la reponse.

ciao...
BruNews, MVP VC++
0
cs_tdeco Messages postés 53 Date d'inscription dimanche 23 février 2003 Statut Membre Dernière intervention 27 mai 2005
5 janv. 2005 à 11:03
Merci de ta réponse, mais je ne pense pas que cela puisse m'aider.
Car en fait mon affichage est commandé par un thread et se fait cycliquement
Je fais:
//Dans mon thread

HWND hBouton = GetDlgItem(hDlg_IHM_MAIN, IDC_IMAGE);
HDC hdc = GetDC(hBouton);
Dessiner_Image(hDlg_IHM_MAIN,hdc,&buffer);
ReleaseDC(hDlg_IHM_MAIN,hdc);

//buffer est un buffer image contenant l'image à afficher

//Ma fonction dessiner
BOOL Dessiner_Image(HWND hDlg,HDC hDC,ClsEm_CVImage *Em_Img)
{

HDC hdcMem = NULL;
HGDIOBJ hbmOld = NULL;
HBITMAP hBmp_Mem;
BITMAPINFO * pMyBitmapInfo;
BYTE * pImage;
int i;


long Hauteur_Img = Em_Img->GetImageHeight();
long Largeur_Img = Em_Img->GetImageWidth();

pMyBitmapInfo = (BITMAPINFO *) calloc(1,sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD));
// pImage = (BYTE*)calloc(1,Largeur_Img*Hauteur_Img);


// initialisation de la palette du bitmap
for ( i=0; i<256; i++)
{
pMyBitmapInfo->bmiColors[i].rgbBlue = i;
pMyBitmapInfo->bmiColors[i].rgbGreen = i;
pMyBitmapInfo->bmiColors[i].rgbRed = i;
pMyBitmapInfo->bmiColors[i].rgbReserved = 0;
}


// initialisation du header du bitmap
pMyBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pMyBitmapInfo->bmiHeader.biWidth = Largeur_Img;
pMyBitmapInfo->bmiHeader.biHeight = Hauteur_Img;
pMyBitmapInfo->bmiHeader.biPlanes = 1;
pMyBitmapInfo->bmiHeader.biBitCount = 8; // nb de bit par pixel
pMyBitmapInfo->bmiHeader.biCompression = 0; // non compressé
pMyBitmapInfo->bmiHeader.biSizeImage = 0;
pMyBitmapInfo->bmiHeader.biXPelsPerMeter = 0;
pMyBitmapInfo->bmiHeader.biYPelsPerMeter = 0;
pMyBitmapInfo->bmiHeader.biClrUsed = 256;
pMyBitmapInfo->bmiHeader.biClrImportant = 0;



hBmp_Mem = CreateDIBSection(hDC, pMyBitmapInfo, DIB_RGB_COLORS, (void**)&pImage, NULL, 0);


for (int j=0;j<Hauteur_Img;j++)
for (int i=0;i<Largeur_Img;i++)
pImage[Largeur_Img*j+i] = Em_Img->m_BufImage[Largeur_Img*(Hauteur_Img-1-j)+i];





hdcMem = CreateCompatibleDC(hDC);
hbmOld = SelectObject(hdcMem, hBmp_Mem); //selection du bitmap


BOOL test = StretchBlt(hDC,0,0,aff_x,aff_y,hdcMem,0,0,Em_Img->GetImageWidth(),Em_Img->GetImageHeight(),SRCCOPY);

BOOL test1 = DeleteDC(hdcMem);
BOOL test2 = DeleteObject(hbmOld);

BOOL test3 = DeleteObject(hBmp_Mem);

if(pMyBitmapInfo!=NULL)
{
free((void *)pMyBitmapInfo);
}
if(pImage!=NULL)
{
free((void **)&pImage);
}

}
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
5 janv. 2005 à 16:15
La zone ou tu affiche ton bitmap, met là en tant que bouton ayant le style OWNER_DRAW dans ton dialogue. Au lieu d'appeler Dessiner pour rafrâichir, appelle InvalidateRect sur le bouton, ce qui va générer le message WM_DRAWITEM. Lors du traitement de ce message (après un rafraichissement de ta part ou tu système), dessine ce ce que tu veux en fonction d'un état global (en l'occurence le buffer avec le bitmap)
0
Rejoignez-nous