Voici le code source d'un début de programme écrit sous Turbo C/C++ permettant d'afficher les caractéristiques d'une image BMP et de l'afficher. Le problème étant l'affichage de la-dite image !!!! Aidez-moi s'il vous plais. Merci.
/*
ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
Ü STS IRIS L.T. LaFayette 77430 Ü
ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ |
Ü Nom du fichier : ETDEBMP3.CPP Ü
Ü Type du fichier : UTILITAIRE | APPLICATION Ü
Ü Sujet : < Affbmp > Ü
Ü Ü
Ü Auteurs : DUFOURNAUD Gr,gory - SERVANT Jean-Michel Ü
Ü Version : 0.7 Beta Ü
Ü Cr,ation : 05/09/2003 Ü
Ü Mise . jour : Aucune (peut-^tre plus tard !!!) Ü
Ü Ü
Ü Acc¦s src : R:\TP\ETDEBMP.CPP Ü
Ü Fabrication : Ü
ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
D,claration des variables |
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <alloc.h>
#include <conio.h>
//char image[12] ;
char pause[1] ;
int cpt, taillefic, i, error, palette ;
unsigned char *mem ;
typedef unsigned short WORD ;
typedef unsigned int UINT ;
typedef unsigned long DWORD ;
typedef long LONG ;
typedef unsigned char BYTE ;
/* bmfh */
typedef struct tagBITMAPFILEHEADER
{
UINT bfType ;
DWORD bfSize ;
UINT bfReserved1 ;
UINT bfReserved2 ;
DWORD bfOffBits ;
} BITMAPFILEHEADER ;
/* bmih */
typedef struct tagBITMAPINFOHEADER
{
DWORD biSize ;
LONG biWidth ;
LONG biHeight ;
WORD biPlanes ;
WORD biBitCount ;
DWORD biCompression ;
DWORD biSizeImage ;
LONG biXPelsPerMeter ;
LONG biYPelsPerMeter ;
DWORD biClrUsed ;
DWORD biClrImportant ;
} BITMAPINFOHEADER ;
/* rgbq */
typedef struct tagRGBQUAD
{
BYTE rgbBlue ;
BYTE rgbGreen ;
BYTE rgbRed ;
BYTE rgbReserved ;
} RGBQUAD ;
BITMAPFILEHEADER bmfh ;
BITMAPINFOHEADER bmih ;
/* bmi */
typedef struct tagBITMAPINFO
{
BITMAPINFOHEADER bmiHeader ;
RGBQUAD bmiColors[1] ;
} BITMAPINFO ;
BITMAPINFO bmi ;
RGBQUAD *aColors ;
BYTE *aBitmapBits ;
char main(int argc, char* argv[])
{
char* image ;
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ Ouverture du fichier |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
/* Mis en m,moire du nom du fichier . ouvrir */
//printf("Entrez le nom du fichier avec l'extension s'il-vous-plait : ") ;
//gets(image) ;
/* V,rification de la syntaxe d'usage */
if (argc == 2)
{
image = argv[1] ;
}
else
{
printf("Erreur de syntaxe !!! \n") ;
printf("Commande d'usage : Etdebmp4.exe [Nom du fichier BMP] \n") ;
return 0;
}
/* Ouverture du fichier mis en argument */
FILE* bm ;
bm = fopen(image,"r") ;
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ V,rification de la pr,sence du dit fichier |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
if (bm == NULL)
{
printf("Le fichier est introuvable. \n") ;
printf("Veuillez r,essayer en tapant le nom du fichier correctement. \n") ;
printf("Merci. \n") ;
error = 1 ;
}
else
{
printf("Le fichier a ,t, correctement ouvert. \n \n") ;
printf("Appuyez sur une touche pour continuer. \n") ;
gets(pause) ;
}
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ Lecture, mise en m,moire et affichage des donn,es du fichier |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
if (error != 1)
{
/* Mise en m,moire des deux premiers octets du fichier pour
l'affichage du type */
mem = (unsigned char*)malloc(2) ;
fread(mem, 1, 2, bm) ;
fseek(bm, SEEK_SET, 0) ;
/* Affichage des donn,es */
fread(&bmfh, sizeof(bmfh), 1, bm) ;
printf("Lecture du BITMAPFILEHEADER : \n \n") ;
printf("Type du fichier : %x soit %c%c \n", bmfh.bfType, mem[0], mem[1]) ;
printf("Taille du fichier : %lu octets \n", bmfh.bfSize) ;
printf("Reserv, (doit ^tre . z,ro) : %d \n", bmfh.bfReserved1) ;
printf("Reserv, (doit ^tre . z,ro) : %d \n", bmfh.bfReserved2) ;
printf("OffBits : %lu \n \n", bmfh.bfOffBits) ;
fread(&bmih, sizeof(bmih), 1, bm) ;
printf("Lecture du BITMAPINFOHEADER : \n \n") ;
printf("Taille : %lu octets \n", bmih.biSize) ;
printf("Dimension du fichier : %d ", bmih.biWidth) ;
printf("x %d pixels \n", bmih.biHeight) ;
printf("Plan (doit ^tre . un) : %d \n", bmih.biPlanes) ;
printf("Nombre de bits par pixel : %d \n", bmih.biBitCount) ;
printf("Compression : %s \n", bmih.biCompression?"Oui":"Non") ;
printf("Taille en bits de l'image : %lu \n", bmih.biSizeImage) ;
printf("R,solution horizontale par pixel : %d \n", bmih.biXPelsPerMeter) ;
printf("R,solution verticale par pixel : %d \n", bmih.biYPelsPerMeter) ;
printf("Nombre de couleurs index,es : %lu \n", bmih.biClrUsed) ;
printf("Nombre de couleurs importantes : %lu \n \n", bmih.biClrImportant) ;
printf("Appuyez sur une touche pour continuer. \n \n") ;
gets(pause) ;
// PREMIERE VERSION DE LA LECTURE DU FICHIER
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ Lecture et mise en m,moire du fichier - PREMIERE VERSION |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
/* Comptage du nombre d'octets du fichier . lire
fseek(bm, 0, SEEK_END) ;
taillefic = ftell(bm) ;
fseek(bm, SEEK_SET, 0) ;
/* Cr,ation du tampon m,moire pour le stockage des donn,es
mem = (unsigned char*)malloc(taillefic) ;
/* Mise en place des donn,es dans la m,moire
fread(mem, 1, taillefic, bm) ;
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ Affichage en clair des donn,es du fichier - PREMIERE VERSION |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
/* Affichage de la signature du fichier
printf("La signature du fichier est : ") ;
printf("%c", mem[0]) ;
printf("%c \n", mem[1]) ;
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ Table des couleurs |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
/* Calcul du nombre de couleurs utilis,es pour la palette
Cr,ation de l'espace m,moire
Lecture des informations de la palette */
palette = (1 << bmih.biBitCount) ;
aColors = (RGBQUAD*)malloc(sizeof(RGBQUAD)*(palette)) ;
fread(aColors, sizeof(RGBQUAD), palette, bm) ;
/* Affichage des couleurs de la palette */
printf("Palette des couleurs : \n \n") ;
for(i = 0 ; i < palette ; i++)
printf("%07x \t Bleu [%d] \t Vert [%d] \t Rouge [%d] \n", i, aColors[i].rgbBlue, aColors[i].rgbGreen, aColors[i].rgbRed) ;
printf("\nAppuyez sur une touche pour continuer. \n \n \n \n") ;
gets(pause) ;
/*ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
³ Affichage de l'image |
+ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ*/
/* Initialisation des pilotes d'affichage */
int gdriver = DETECT, gmode, errorcode ;
struct palettetype pal ;
char psize[80], pval[20] ;
int i, ht, xmax ;
int y = 10 ;
initgraph(&gdriver, &gmode, "") ;
/* V,rification d'erreur */
errorcode = graphresult() ;
if (errorcode != grOk)
{
printf("Erreur graphique : %s \n", grapherrormsg(errorcode)) ;
printf("Appuyez sur une touche pour continuer.") ;
gets(pause) ;
/* Termine la session si erreur */
exit(1) ;
}
/* R,cup,ration de la palette */
getpalette(&pal) ;
/* Affichage des informations de la palette */
sprintf(psize, "La palette contient %d couleurs.", pal.size) ;
/* Affichage des informations de la palette */
outtextxy(0, y, psize) ;
if (pal.size != 0)
{
ht = textheight("W") ;
y += 2*ht ;
outtextxy(0, y, "Voici le code hexad,cimal des couleurs utilis,es :") ;
y += 2*ht ;
for (i = 0 ; i < pal.size ; i++, y+=ht)
{
sprintf(pval, "Palette[%02d] : [0x%02x]", i, pal.colors[i]) ;
outtextxy(0, y, pval) ;
}
gets(pause) ;
}
/* Cr,ation de la palette */
for (i = 0; i < pal.size ; i++)
setrgbpalette(pal.colors[i], aColors[i].rgbBlue, aColors[i].rgbGreen, aColors[i].rgbRed) ;
/* display the gray scale */
ht = getmaxy() / pal.size;
xmax = getmaxx();
y = 0;
for (i=0; i<pal.size; i++)
{
setfillstyle(SOLID_FILL, i);
bar(0, y, xmax, y+ht);
y += ht;
}
int a, b, rgb[3] ;
fseek(bm, 54, SEEK_SET) ;
for (b = bmih.biHeight ; b > 0 ; b--)
{
for (a = 0 ; a < bmih.biWidth ; a++)
{
rgb[0] = fgetc(bm) ;
rgb[1] = fgetc(bm) ;
rgb[2] = fgetc(bm) ;
}
}
/* Lib,ration de la m,moire utilis,e */
getch();
closegraph();
fclose(bm) ;
}
return 0 ;
}
Merci encore pour votre aide précieuse.