PB d'affichage de bitmap

PB d'affichage de bitmap - C++ - Programmation

Marsh Posté le 21-06-2002 à 11:58:37    

Salut ,  
 
j'ais gros pb lorsque j'essaye d'afficher un bitmap à l'écran :  
la fonction CreateDIBitmap(...) qui créé mon image ne fonctionne  
pas toujours.  
Le premier affichage marche correctement mais quand j'ouvre une autre fenêtre en parallèle et que j'essaye d'afficher la même image cela ne  
marche plus ( le CreateDIBitmap ne me créé plus le bitmap )  
 
ci-dessous mon code  
si qq un pouvais m'aider  
il me sauverait la vie  
merci d'avance pour votre aide  
 
a+  
 
 
 
 
 
 
 
HANDLE hDIB ; // variables utilisées pour la  
BITMAPINFOHEADER * infoHeader ; // création du bitmap affiché  
BITMAPINFO * infoDib ;  
 
/**  
* Pointeur sur l'image BMP affiché à l'écran.  
*/  
Graphics::TBitmap * imgDisplayed ;  
 
hDIB = GlobalAlloc(GMEM_MOVEABLE, sizeof(BITMAPINFO) + largeur * img->getYImg() ) ;  
 
infoDib = (LPBITMAPINFO) GlobalLock(hDIB) ;  
infoHeader = (LPBITMAPINFOHEADER) infoDib ;  
 
// Construction de l'info header du bmp qui sera affiché  
 
infoHeader->biSize = sizeof(BITMAPINFOHEADER) ;  
infoHeader->biWidth = largeur ;  
infoHeader->biHeight = - img->getYImg() ;  
infoHeader->biPlanes = 1 ;  
infoHeader->biBitCount = bpp ;  
infoHeader->biCompression = 0 ;  
infoHeader->biSizeImage = 0 ;  
infoHeader->biXPelsPerMeter = 0 ;  
infoHeader->biYPelsPerMeter = 0 ;  
infoHeader->biClrUsed = 0 ;  
infoHeader->biClrImportant = 0 ;  
 
infoDib->bmiHeader = *infoHeader ;  
 
// Construction de la nouvelle palette  
 
int center = static_cast<int> (img->getCenterGreyLevel()[ currentSlice ]) ;  
int width = static_cast<int> (img->getWidthGreyLevel()[ currentSlice ]) ;  
int ptaille1 = center - width / 2 ;  
int ptaille2 = center + width / 2 ;  
 
for ( int i = 0 ; i <= ptaille1 ; i++ )  
{  
infoDib->bmiColors[i].rgbBlue = infoDib->bmiColors[i].rgbGreen = infoDib->bmiColors[i].rgbRed = (BYTE) 0 ;  
infoDib->bmiColors[i].rgbReserved = (BYTE) 0 ;  
}  
 
for ( int i = ptaille1 + 1 ; i < ptaille2 ; i++ )  
{  
infoDib->bmiColors[i].rgbBlue = infoDib->bmiColors[i].rgbGreen = infoDib->bmiColors[i].rgbRed = (BYTE)(255*(i - ptaille1 )/ width );  
infoDib->bmiColors[i].rgbReserved = (BYTE) 0 ;  
}  
 
for (int i = ptaille2 ; i < 256 ; i++ )  
{  
infoDib->bmiColors[i].rgbBlue = infoDib->bmiColors[i].rgbGreen = infoDib->bmiColors[i].rgbRed = (BYTE) 255 ;  
infoDib->bmiColors[i].rgbReserved = (BYTE) 0;  
}  
 
// Destruction de l'ancien handle de bitmap  
 
if ( imgDisplayed != NULL )  
{  
HBITMAP hbmp = imgDisplayed->ReleaseHandle() ;  
DeleteObject( hbmp ) ;  
delete imgDisplayed ;  
}  
 
// Création du nouveau handle de bitmap  
 
imgDisplayed = new Graphics::TBitmap ;  
 
// Chargement de l'image  
 
imgDisplayed->Handle = CreateDIBitmap( GetDC( owner->Handle ) , infoHeader , CBM_INIT , img->getImgData()[ currentSlice ] , infoDib , DIB_RGB_COLORS ) ;

Reply

Marsh Posté le 21-06-2002 à 11:58:37   

Reply

Marsh Posté le 21-06-2002 à 12:49:00    

Solution : essaye la SDL ou Allegro  [:yaisse1v]
 
Exemple avec ALlegro:
 
------------------------
BITMAP* mon_bitmap;
 
//charge le bitmap
mon_bitmap = load_bitmap("Mon_bitmap.bmp" );
 
//Dessine le bitmap aux coordonnées (0,0)
draw_bitmap(screen, mon_bitmap, 0,0);
-------------------------
 
C'est pas plus simple, non??


Message édité par ITM le 21-06-2002 à 12:50:57

---------------
iteme.free.fr | Mon feedback
Reply

Marsh Posté le 21-06-2002 à 13:32:33    

j'allais le dire.
si tu veux des infos : www.allegro.cc

Reply

Marsh Posté le 21-06-2002 à 13:37:20    

Va voir sur mon site, j'ai même fait un tutorial pour débuter ;)


---------------
iteme.free.fr | Mon feedback
Reply

Marsh Posté le 24-06-2002 à 10:37:34    

ok merci  :jap:

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed