IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Probleme dans la lecture d�un bmp


Sujet :

C++

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre �clair�
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    487
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Octobre 2007
    Messages : 487
    Par d�faut Probleme dans la lecture d�un bmp
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    // bmp1.cpp : Defines the entry point for the console application.
    //
     
    #include "stdafx.h"
    #include <windows.h>
    #include <fstream.h>
     
     
     
    class CRaster {
    	public:
    		int Width,Height;		// Dimensions
    		int BPP;				// Bits Per Pixel.
    		char * Raster;			// Bits of the Image.
    		RGBQUAD * Palette;		// RGB Palette for the image.
    		int BytesPerRow;		// Row Width (in bytes).
    		BITMAPINFO * pbmi;		// BITMAPINFO structure
     
    		// Member functions (defined later):
    		int LoadBMP (char * szFile);
    		int GDIPaint (HDC hdc,int x,int y);
    };
    int CRaster::LoadBMP (char * szFile)
    {	
    	BITMAPFILEHEADER bmfh;
    	BITMAPINFOHEADER bmih;
     
    	// Open file.
    	ifstream bmpfile (szFile , ios::in | ios::binary);
    	if (! bmpfile.is_open()){cout<<"Erreur"; return 1;	}	// Error opening file
     
    	// Load bitmap fileheader & infoheader
    	bmpfile.read ((char*)&bmfh,sizeof (BITMAPFILEHEADER));
    	bmpfile.read ((char*)&bmih,sizeof (BITMAPINFOHEADER));
     
    	// Check filetype signature
    	if (bmfh.bfType!='MB') return 2;		// File is not BMP
     
    	// Assign some short variables:
    	BPP=bmih.biBitCount;
    	Width=bmih.biWidth;
    	Height= (bmih.biHeight>0) ? bmih.biHeight : -bmih.biHeight; // absoulte value
    	BytesPerRow = Width * BPP / 8;
    	BytesPerRow += (4-BytesPerRow%4) % 4;	// int alignment
     
    	// If BPP aren't 24, load Palette:
    	if (BPP==24) pbmi=(BITMAPINFO*)new char [sizeof(BITMAPINFO)];
    	else
    	{
    		pbmi=(BITMAPINFO*) new char[sizeof(BITMAPINFOHEADER)+(1<<BPP)*sizeof(RGBQUAD)];
    		Palette=(RGBQUAD*)((char*)pbmi+sizeof(BITMAPINFOHEADER));
    		bmpfile.read ((char*)Palette,sizeof (RGBQUAD) * (1<<BPP));
    	}
    	pbmi->bmiHeader=bmih;
     
    	// Load Raster
    	bmpfile.seekg (bmfh.bfOffBits,ios::beg);
     
    	Raster= new char[BytesPerRow*Height];
     
    	// (if height is positive the bmp is bottom-up, read it reversed)
    	if (bmih.biHeight>0)
    		for (int n=Height-1;n>=0;n--)
    			bmpfile.read (Raster+BytesPerRow*n,BytesPerRow);
    	else
    		bmpfile.read (Raster,BytesPerRow*Height);
     
    	// so, we always have a up-bottom raster (that is negative height for windows):
    	pbmi->bmiHeader.biHeight=-Height;
     
    	bmpfile.close();
     
    	return 0;
    }
     
     
    int main(void){
    	CRaster a;
    	a.LoadBMP("d:\\test.bmp");
     
    	return 0;
    }

  2. #2
    Expert �minent
    Avatar de M�dinoc
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 397
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 41
    Localisation : France

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 397
    Par d�faut
    Et quel est pr�cis�ment le probl�me?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parl� avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Membre exp�riment�
    Inscrit en
    Octobre 2007
    Messages
    285
    D�tails du profil
    Informations personnelles :
    �ge : 44

    Informations forums :
    Inscription : Octobre 2007
    Messages : 285
    Par d�faut
    Citation Envoy� par M�dinoc Voir le message
    Et quel est pr�cis�ment le probl�me?
    T'es pas joueur, suffit de chercher Charlie...

  4. #4
    Membre exp�riment�
    Inscrit en
    Octobre 2007
    Messages
    285
    D�tails du profil
    Informations personnelles :
    �ge : 44

    Informations forums :
    Inscription : Octobre 2007
    Messages : 285
    Par d�faut
    J'ai trouv� charlie...

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    int main(int argc, char* argv[]){
        CRaster a;
        a.LoadBMP("F:\\charlie.bmp");
        return 0;
    }
    Plus s�rieusement, apr�s test, la fonction � l'air de marcher

Discussions similaires

  1. R�ponses: 5
    Dernier message: 19/11/2009, 12h23
  2. R�ponses: 6
    Dernier message: 16/11/2009, 08h42
  3. Probleme GTK C Lecture dans un Text_Buffer
    Par mazareth dans le forum C
    R�ponses: 1
    Dernier message: 01/06/2009, 20h43
  4. probleme windows form, lecture dans un fichier texte
    Par fbarbin dans le forum Windows Forms
    R�ponses: 2
    Dernier message: 08/09/2008, 14h06
  5. Lecture d�un bmp
    Par dot-_-net dans le forum D�buter
    R�ponses: 6
    Dernier message: 31/03/2008, 22h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo