Affichage BMP

Chapi72 Messages postés 15 Date d'inscription mardi 23 novembre 2004 Statut Membre Dernière intervention 25 mai 2005 - 18 janv. 2005 à 10:24
bayeto Messages postés 224 Date d'inscription mardi 12 août 2003 Statut Membre Dernière intervention 18 octobre 2010 - 18 janv. 2005 à 17:50
Bonjour,



je voudrais juste charger une image bmp et l'afficher à l'écran. Le
problème se situe pour rendre compatible le dc bmp et le dc
d'affichage. Voici mon code et les erreurs que celui-ci me done (je
programme en VC++6.0) Merci d'avance.





void CAffichageBMPDlg::OnBitmap()

{

HBITMAP hBitmap = (HBITMAP)
::LoadImage(AfxGetInstanceHandle(),"bacterie.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);

if (hBitmap != NULL)

{

MessageBox("Image chargée","Information",MB_ICONINFORMATION|MB_OK);

}

else

{

MessageBox("Image non chargée!","Erreur",MB_ICONERROR|MB_OK);

}

m_bmpBitmap.Attach(hBitmap);



BITMAP bm;



m_bmpBitmap.GetBitmap(&bm);



CPaintDC dc(this);

CDC dcMem;



dcMem.CreateCompatibleDC(dc);

dcMem.SelectObject(&m_bmpBitmap);



dc->BitBlt(10,10,bm.bmWidth,bm.bmHeight,&dcMem,0,0,SRCCOPY);

}



--------------------Configuration: affichageBMP - Win32 Debug--------------------

Compiling...

affichageBMPDlg.cpp

H:\MES DOCUMENTS\VisualC\Janvier\AffichageBMP\affichageBMPDlg.cpp(194)
: error C2664: 'CreateCompatibleDC' : cannot convert parameter 1 from
'class CPaintDC' to 'class CDC *'

No user-defined-conversion
operator available that can perform this conversion, or the operator
cannot be called

H:\MES DOCUMENTS\VisualC\Janvier\AffichageBMP\affichageBMPDlg.cpp(197)
: error C2819: type 'CPaintDC' does not have an overloaded member
'operator ->'

c:\program files\microsoft
visual studio\vc98\mfc\include\afxwin.h(1012) : see declaration of
'CPaintDC'

H:\MES DOCUMENTS\VisualC\Janvier\AffichageBMP\affichageBMPDlg.cpp(197)
: error C2227: left of '->BitBlt' must point to class/struct/union

Error executing cl.exe.



affichageBMP.exe - 3 error(s), 0 warning(s)

3 réponses

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
18 janv. 2005 à 12:20
dc n'est pas un pointeur :

dcMem.CreateCompatibleDC(&dc);

dc.BitBlt(10,10,bm.bmWidth,bm.bmHeight,&dcMem,0,0,SRCCOPY);
0
Chapi72 Messages postés 15 Date d'inscription mardi 23 novembre 2004 Statut Membre Dernière intervention 25 mai 2005
18 janv. 2005 à 15:19
Tout d'abord merci pour ta réponse.

Alors ça compile bien maintenant mais aucune image ne s'affiche!



La fonction appartient à une classe de type CDialog. L'erreur vient-elle de là ?



Merci d'avance
0
bayeto Messages postés 224 Date d'inscription mardi 12 août 2003 Statut Membre Dernière intervention 18 octobre 2010
18 janv. 2005 à 17:50
Il me semble que les CPaintDC s'emploient uniquement en reponse à un WM_PAINT, soit OnPaint dans ton cas.

Charge ton image dans une variable membre de ta classe fenêtre et peinds-la dans OnPaint.

Je pense que OnBitmap est la reponse à la commande IDC_BITMAP non? Si c'est le cas, essaye ca:

void CAffichageBMPDlg::OnBitmap()
{
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),"bacterie.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if (hBitmap != NULL)
{
MessageBox("Image chargée","Information",MB_ICONINFORMATION|MB_OK);
}
else
{
MessageBox("Image non chargée!","Erreur",MB_ICONERROR|MB_OK);
}
m_bmpBitmap.Attach(hBitmap);

}

void CAffichageBMPDlg::OnPaint()
{
CPaintDC dc(this);
//code par default de OnPaint

if(m_bmpBitmap.GetObjectType() != OBJ_BITMAP)
return;

CDC dcMem;

dcMem.CreateCompatibleDC(&dc);
dcMem.SelectObject(&m_bmpBitmap);

dc->BitBlt(10,10,bm.bmWidth,bm.bmHeight,&dcMem,0,0,SRCCOPY);
dc->DeleteDC();
}
0
Rejoignez-nous