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++Builder Discussion :

Retourner horizontalement une image BMP c++ builder 6


Sujet :

C++Builder

  1. #1
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Avril 2013
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Avril 2013
    Messages : 29
    Par défaut Retourner horizontalement une image BMP c++ builder 6
    Bonjour,
    Je débute dans builder 6 et je bloque sur un problème simple.
    Je voudrais retourner une image horizontalement.
    L'image à retourner est stockée dans un Image1->Picture->Bitmap et je souhaite afficher l'image retournée dans Image2->Picture->Bitmap.
    Sous visual c++, une fonction simple existe mais pas sous builder ... enfin je crois.
    Le code doit être le plus rapide possible.
    Y'a-t-il un moyen de copier les colonnes entières d'un coup ou c'est du pixel à pixel ?
    Merci d'avance.

    PS : j'ai bcp cherché sur google avant de poster

  2. #2
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Avril 2013
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Avril 2013
    Messages : 29
    Par défaut retourner un BMP (Miroir horizontal)
    Bonjour,
    J'ai trouvé une bibliotèque pour la gestion des images simple à utiliser (bitmapEx.cpp) mais elle me retourne une erreur sur la fonction bitmapEx->Load(_T(chemin));
    Elle me retourne une erreur "Acces violation at adress 00402986 in module 'camera.exe'. Read of adress 0000044C."
    elle pointe dans bitmapEX.cpp sur la dernière ligne de :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    void CBitmapEx::Load(LPTSTR lpszBitmapFile)
    {
    	// Check for valid .BMP file path
    	if (lpszBitmapFile != NULL)
    	{
    		// Open .BMP file
    		FILE* file = _tfopen(lpszBitmapFile, _T("rb"));
     
    		if (file != NULL)
    		{
    			// Deinit members
    			if (m_lpData != NULL)
    Elle a été modifiée pour être utilisée avec builder (de visual c++), le pb vient peut être le là.
    Si quelqu'un connait une bibliotèque c++ builder qui permêt de retourner horizontalement un bmp, je suis preneur.

    Cordialement

  3. #3
    Membre Expert
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Par défaut
    Salut, normalement c'est le genre de tâche que tu peux faire avec ScanLine.

    J'ai peut-être un bout de code qui fais cela, mais je ne l'ai pas avec moi maintenant. Si tu ne trouve pas d'ici demain, je vais le poster ici.

  4. #4
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Avril 2013
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Avril 2013
    Messages : 29
    Par défaut retourner un BMP (Miroir horizontal)
    Bonjour,
    Je n'ai toujours pas réussi à faire ce que je voulais mais je travail sur la fonction scanline. Il faut vraiment que je comprenne le fondement de la fonction pour comprendre comment l'utiliser.
    Je n'ai pas règlé mon problème de library bitmapEx, à chaque load, j'ai un plantage que je n'ai pas avec TBitmap.
    Par contre, pour mélanger deux images bitmap, ça ne doit pas être simple avec TBitmap ? bitmapEx avait bcp de fonctions évoluées implémentées d'office.
    Cordialement

  5. #5
    Membre Expert
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Par défaut
    Salut, voici du code que j'avais fais en 2003 (je crois). Dis-moi si ça fonctionne:
    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
    //---------------------------------------------------------------------------
    /*
     * Fontion pour retourner l'image verticalement
     */
    void FlipV(Graphics::TBitmap *ImAModifier)
    {
    ImAModifier->Canvas->CopyRect( Rect(0, ImAModifier->Height-1, ImAModifier->Width, -1),
                    ImAModifier->Canvas,
                    Rect(0, 0, ImAModifier->Width, ImAModifier->Height) );
     
    }
    //---------------------------------------------------------------------------
    /*
     * Fontion pour retourner l'image horizontalement
     */
    void FlipH(Graphics::TBitmap *ImAModifier)
    {
    ImAModifier->Canvas->CopyRect( Rect(ImAModifier->Width-1, 0, -1, ImAModifier->Height),
                    ImAModifier->Canvas,
                    Rect(0, 0, ImAModifier->Width, ImAModifier->Height) );
    }

  6. #6
    Membre confirmé
    Inscrit en
    Août 2010
    Messages
    123
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 123
    Par défaut
    Tu peux aussi regarder la bibliothèque jAPI (en post it sur ce forum).

    A mon avis il existe surement dedans une fonction pour faire ça, et tu peux t'en inspirer.

    Cordialement.

  7. #7
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Avril 2013
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Avril 2013
    Messages : 29
    Par défaut retourner un BMP (Miroir horizontal)

    UN GRAND MERCI A TOI CRAYON, je pense franchement que je n'aurais jamais trouvé sans coup de main, j'étais vraiment bloqué.
    Pourtant, ce n'est pas faute d'avoir chercher.
    J'ai mis la fonction dans un timer pour afficher le BMP comme une vidéo mais ça lag franchement (image noir entre les bmp ... ça pique les yeux). Je pense qu'il doit y avoir une astuce pour éviter ça...

    Merci à toi aussi POCOYote, je vais jeter de suite un oeil à jAPI.

    A+

  8. #8
    Membre émérite
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Par défaut
    http://www.developpez.net/forums/d11...-image-timage/


    /////////////////////////////////////////

    http://www.leunen.com/cbuilder/rotbmp.html

    Utilisation de GDI+ pour effectuer une rotation

    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
     
     
      Gdiplus::Graphics graphics(hdc);
      Gdiplus::Image image(L"YourPicture.gif");
     
      //First sample
      //90° rotation and vertical flip
      graphics.DrawImage(&image, 10, 10, image.GetWidth(), image.GetHeight());
      image.RotateFlip(Gdiplus::Rotate90FlipY);
      graphics.DrawImage(&image, 200, 10);
     
     
     
      //Second sample
      //Rotate by arbitrary angle
      //Warning: the rotation is performed from the origin (0,0).
      //All the device context (window) is rotated, not only the image.
      //First draw not-rotated image
      graphics.DrawImage(&image,0,100);
      //make a translation to make it visible at the right of the first image
      graphics.TranslateTransform(260.0f,80.0f);
      //rotate
      graphics.RotateTransform(45.0f);
      //draw rotated image
      graphics.DrawImage(&image,0,0);

  9. #9
    Membre Expert
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Par défaut
    Citation Envoyé par reptooyep Voir le message
    J'ai mis la fonction dans un timer pour afficher le BMP comme une vidéo mais ça lag franchement (image noir entre les bmp ... ça pique les yeux). Je pense qu'il doit y avoir une astuce pour éviter ça...
    Normalement pour éviter ça il te faut un système de "double buffer". Et si tu dessines directement sur le Canvas de ta form c'est vraiment plus vite que d'utiliser un composant TImage.

  10. #10
    Membre Expert

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    1 407
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 1 407
    Par défaut
    Salut !

    Développé (jadis sous Windows 98) avec BCB3 Pro mais testé sous XP et Windows 7...
    En partant du principe que le bitmap source n'est jamais modifié...
    Voici les exemples en utilisant ScanLine :

    Le .h :

    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
    //-------------------
    #ifndef Unit1H
    #define Unit1H
    //-------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <Dialogs.hpp>
    #include <Menus.hpp>
    //-------------------
    class jRgb
    {
    public :
    BYTE b;
    BYTE g;
    BYTE r;
    };
    //-------------------
    class TForm1 : public TForm
    {
    __published:	// Composants gérés par l'EDI
        TMainMenu *MainMenu1;
        TOpenDialog *OpenDialog1;
        TMenuItem *File1;
        TMenuItem *Open1;
        TMenuItem *Quit1;
        TMenuItem *Edit1;
        TMenuItem *FlipV1;
        TMenuItem *FlipH1;
        TMenuItem *Rot901;
        TMenuItem *Rot1801;
        TMenuItem *Rot2701;
        TMenuItem *Source1;
     
        void __fastcall Open1Click(TObject *Sender);
        void __fastcall Quit1Click(TObject *Sender);
        void __fastcall FormPaint(TObject *Sender);
        void __fastcall FlipV1Click(TObject *Sender);
        void __fastcall FlipH1Click(TObject *Sender);
        void __fastcall Rot901Click(TObject *Sender);
        void __fastcall Rot1801Click(TObject *Sender);
        void __fastcall Rot2701Click(TObject *Sender);
        void __fastcall Source1Click(TObject *Sender);
    private:	// Déclarations de l'utilisateur
    public:		// Déclarations de l'utilisateur
        __fastcall TForm1(TComponent* Owner);
    };
    //-------------------
    extern PACKAGE TForm1 *Form1;
    //-------------------
    #endif
    Le .cpp :

    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    //-------------------
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //-------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
     
    Graphics::TBitmap *Srce = new Graphics::TBitmap;
    Graphics::TBitmap *Dest = new Graphics::TBitmap;
     
    //-------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    }
    //-------------------
     
    void __fastcall TForm1::Open1Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
        {
        Srce->LoadFromFile(OpenDialog1->FileName);
        Dest->LoadFromFile(OpenDialog1->FileName);
        }
    Repaint();
    }
    //-------------------
    void __fastcall TForm1::Quit1Click(TObject *Sender)
    {
    delete Srce;
    delete Dest;
    Close();
    }
    //-------------------
    void __fastcall TForm1::FormPaint(TObject *Sender)
    {
    if(Dest != NULL) Canvas->Draw(0,0, Dest);    
    }
    //-------------------
    void __fastcall TForm1::Source1Click(TObject *Sender)
    {
    int y;
    int we = Srce->Width;
    int he = Srce->Height;
    Dest->Width  = we;
    Dest->Height = he;
     
    switch(Srce->PixelFormat)
        {
        case pf8bit :
        for(y = 0; y < he; y++)
            {
            CopyMemory(Dest->ScanLine[y], Srce->ScanLine[y],  we);
            }
        break;
     
        case pf24bit :
        for(y = 0; y < he; y++)
            {
            CopyMemory( Dest->ScanLine[y], Srce->ScanLine[y], we * 3);
            }
        break;
        }
    Repaint();
    }
    //-------------------
    void __fastcall TForm1::FlipV1Click(TObject *Sender)
    {
    int x, y;
    int we = Srce->Width;
    int he = Srce->Height;
    int w = we-1;
    Dest->Width  = we;
    Dest->Height = he;
     
    BYTE *S, *D;
    jRgb *pS, *pD;
     
    switch(Srce->PixelFormat)
        {
        case pf8bit :
        for(y = 0; y < he; y++)
            {
            S = (BYTE*)Srce->ScanLine[y];
            D = (Byte*)Dest->ScanLine[y];
            for(x=0; x < we; x++)
                {
                D[w-x]=S[x];
                }
            }
        break;
     
        case pf24bit :
        for(y = 0; y < he; y++)
            {
            pS = (jRgb*)Srce->ScanLine[y];
            pD = (jRgb*)Dest->ScanLine[y];
            for(x=0; x < we; x++)
                {
                pD[w-x].r = pS[x].r;
    	        pD[w-x].g = pS[x].g;
                pD[w-x].b = pS[x].b;
    	        }
            }
        break;
        }
    Repaint();
    }
    //-------------------
    void __fastcall TForm1::FlipH1Click(TObject *Sender)
    {
    int x, y;
    int we = Srce->Width;
    int he = Srce->Height;
    int h = he-1;
    Dest->Width  = we;
    Dest->Height = he;
     
    BYTE *S, *D;
    jRgb *pS, *pD;
     
    switch(Srce->PixelFormat)
        {
        case pf8bit :
        for(y = 0; y < he; y++)
            {
            S = (BYTE*)Srce->ScanLine[y];
            D = (Byte*)Dest->ScanLine[h - y];
            for(x=0; x < we; x++)
                {
                D[x]=S[x];
                }
            }
        break;
     
        case pf24bit :
        for(y = 0; y < he; y++)
            {
            pS = (jRgb*)Srce->ScanLine[y];
            pD = (jRgb*)Dest->ScanLine[h - y];
            for(x=0; x < we; x++)
                {
                pD[x].r = pS[x].r;
    	        pD[x].g = pS[x].g;
                pD[x].b = pS[x].b;
    	        }
            }
        break;
        }
    Repaint();
    }
    //-------------------
    void __fastcall TForm1::Rot901Click(TObject *Sender)
    {
    int x, y;
    int we = Srce->Width;
    int he = Srce->Height;
    int w = we-1;
    int h = he-1;
    // rotation imposant une modification des dimensions
    Dest->Width  = he;
    Dest->Height = we;
     
    BYTE *S, *D;
    jRgb *pS, *pD;
     
    switch(Srce->PixelFormat)
        {
        case pf8bit :
        for(y = 0; y < he; y++)
            {
            S = (BYTE*)Srce->ScanLine[y];
            D = (Byte*)Dest->ScanLine[h - y];
            for(x=0; x < we; x++)
                {
                D[x]=S[x];
                }
            }
        break;
     
        case pf24bit :
        for(y = 0; y < he; y++)
            {
            pS = (jRgb*)Srce->ScanLine[y];
            for(x=0; x < we; x++)
                {
                pD = (jRgb*)Dest->ScanLine[w - x];
                pD[h-y].r = pS[w-x].r;
    	        pD[h-y].g = pS[w-x].g;
                pD[h-y].b = pS[w-x].b;
    	        }
            }
        break;
        }
    Repaint();
    }
    //-------------------
    void __fastcall TForm1::Rot1801Click(TObject *Sender)
    {
    int x, y;
    int we = Srce->Width;
    int he = Srce->Height;
    int w = we-1;
    int h = he-1;
    Dest->Width  = we;
    Dest->Height = he;
     
    BYTE *S, *D;
    jRgb *pS, *pD;
     
    switch(Srce->PixelFormat)
        {
        case pf8bit :
        for(y = 0; y < he; y++)
            {
            S = (BYTE*)Srce->ScanLine[y];
            D = (Byte*)Dest->ScanLine[h - y];
            for(x=0; x < we; x++)
                {
                D[w- x] = S[x];
                }
            }
        break;
     
        case pf24bit :
        for(y = 0; y < he; y++)
            {
            pS = (jRgb*)Srce->ScanLine[y];
            pD = (jRgb*)Dest->ScanLine[h - y];
            for(x=0; x < we; x++)
                {
                pD[w-x].r = pS[x].r;
    	        pD[w-x].g = pS[x].g;
                pD[w-x].b = pS[x].b;
    	        }
            }
        break;
        }
    Repaint();
    }
    //-------------------
    void __fastcall TForm1::Rot2701Click(TObject *Sender)
    {
    int x, y;
    int we = Srce->Width;
    int he = Srce->Height;
    int w = we-1;
    // rotation imposant une modification des dimensions
    Dest->Width  = he;
    Dest->Height = we;
     
    BYTE *S, *D;
    jRgb *pS, *pD;
     
    switch(Srce->PixelFormat)
        {
        case pf8bit :
        for(y = 0; y < he; y++)
            {
            S = (BYTE*)Srce->ScanLine[y];
            for(x=0; x < we; x++)
                {
                D = (Byte*)Dest->ScanLine[w - x];
                D[y] = S[x];
                }
            }
        break;
     
        case pf24bit :
        for(y = 0; y < he; y++)
            {
            pS = (jRgb*)Srce->ScanLine[y];
            for(x=0; x < we; x++)
                {
                pD = (jRgb*)Dest->ScanLine[w - x];
                pD[y].r = pS[x].r;
    	        pD[y].g = pS[x].g;
                pD[y].b = pS[x].b;
    	        }
            }
        break;
        }
    Repaint();
    }
    //-------------------
    A plus !

Discussions similaires

  1. Réponses: 12
    Dernier message: 22/02/2005, 17h45
  2. Réponses: 2
    Dernier message: 19/11/2004, 08h54
  3. [C#] Comment convertir une image bmp en jpg !!!
    Par vandeyy dans le forum Windows Forms
    Réponses: 5
    Dernier message: 13/07/2004, 20h37
  4. inserer une image BMP dans un fichier rtf
    Par Alice9 dans le forum MFC
    Réponses: 17
    Dernier message: 06/07/2004, 10h31
  5. [BPW] Impression d'une image BMP
    Par Alcatîz dans le forum Turbo Pascal
    Réponses: 13
    Dernier message: 21/08/2003, 14h34

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