Sauvegarder

Résolu
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 - 18 nov. 2006 à 15:46
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 - 18 nov. 2006 à 18:05
Salut:

Etant donné un HBITMAP comment le sauvegarder dans un fichier?

5 réponses

cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 9
18 nov. 2006 à 17:06
j'ai fait la recherche sur google et ca ne m'a meme pas prit une minute pour trouver la fonction, la prochaine fois cherche un peu plus :)

void 
SaveBitmap(char *szFilename,HBITMAP hBitmap)

{

      HDC       
hdc=NULL;

      FILE*     
fp=NULL;

      LPVOID     pBuf=NULL;

      BITMAPINFO bmpInfo;

      BITMAPFILEHEADER 
bmpFileHeader; 

      do{ 

            hdc=GetDC(NULL);

            ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));

           
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);

           
GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS); 

           
if(bmpInfo.bmiHeader.biSizeImage<=0)

bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;

            if((pBuf =
malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)

            {

                  MessageBox(
NULL, "Unable to Allocate Bitmap Memory", "Error", MB_OK|MB_ICONERROR);

                  break;

            }           

           
bmpInfo.bmiHeader.biCompression=BI_RGB;

           
GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo,
DIB_RGB_COLORS);       

            if((fp =
fopen(szFilename,"wb"))==NULL)

            {

                  MessageBox(
NULL, "Unable to Create Bitmap File", "Error", MB_OK|MB_ICONERROR);

                  break;

            } 

           
bmpFileHeader.bfReserved1=0;

           
bmpFileHeader.bfReserved2=0;

           
bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;

           
bmpFileHeader.bfType='MB';

           
bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); 

            fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);

            fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);

           
fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp); 

      }while(false); 

            if(hdc)    
ReleaseDC(NULL,hdc); 

            if(pBuf)   
free(pBuf); 

            if(fp)     
fclose(fp);

}

Bob...

"Vaut mieux se taire et passer pour un con, que de l'ouvrir et ne laisser aucun doute sur le sujet..."
3
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
18 nov. 2006 à 17:09
Salut Ombitious !

Vas voir dans ma source tracé de courbes :
Tracé de courbes à partir d'un fichier texte (GDI)

Tu trouveras ton bonheur dans le fichier "Bitmap.h".

YOYO, @+.
"L'intelligence c'est comme un parachute, quand on en n'a pas...on s'écrase !"
3
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
18 nov. 2006 à 17:12
Ah mer.. ! Je suis pas prems ! lol
Dans ce que je t'ai dit il y a des commentaires par contre, tu as le choix maintenant.
C'est y pas beau ça ?

YOYO, @+.
"L'intelligence c'est comme un parachute, quand on en n'a pas...on s'écrase !"
0
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
18 nov. 2006 à 18:01
Salut:

Merci [auteurdetail.aspx?ID=17350 LordBob], [auteurdetail.aspx?ID=235265 yoyo269] 

les deux codes sont performants.
0

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

Posez votre question
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
18 nov. 2006 à 18:05
Pas de quoi !

YOYO, @+.
"L'intelligence c'est comme un parachute, quand on en n'a pas...on s'écrase !"
0
Rejoignez-nous