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

Windows Discussion :

Pb de creation d'un Bitmap


Sujet :

Windows

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    527
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 527
    Points : 215
    Points
    215
    Par défaut Pb de creation d'un Bitmap
    Bonjour,

    J'essaie de creer un Bitmap, un cercle noir en tracé pointillé sur fond blanc
    que je voudrais par la suite superposer à un second Bitmap
    Apres passage dans ma procedure je récupère un cercle blanc sur fond noir !
    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
    HBITMAP MakeBmpEllipse (HDC hdc, RECT rin)
    {
    HDC hdctemp;
    HBITMAP  hbmpTemp;
    
       hdctemp = CreateCompatibleDC (hdc);
       hbmpTemp = CreateCompatibleBitmap (hdc, rin.right, rin.bottom);
       SelectObject (hdctemp, hbmpTemp);
       SetBkColor(hdctemp, RGB(255,255,255));
       SetBkMode(hdctemp, TRANSPARENT);
       Ellipse (hdctemp, rin.left, rin.top, rin.right, rin.bottom);
       DeleteDC(hdctemp);
    
    return hbmpTemp;
    }
    Quelqu'un peut m'expliquer avec le GDI comment je pourrais arriver à creer cela ?

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 379
    Points : 41 573
    Points
    41 573
    Par défaut
    CreateCompatibleBitmap() sur un DC nouvellement créé donne un bitmap monochrome.
    Essaie CreateDIBSection() à la place, pour créer un bitmap DIB.

    De plus, tu détruis mal ton DC: Il faut restaurer l'ancien bitmap avant:
    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
    HBITMAP MakeBmpEllipse (HDC hdc, RECT rin)
    {
    HDC hdctemp;
    HBITMAP  hbmpTemp;
    HGDIOBJ hOldBmp;
    
       hdctemp = CreateCompatibleDC (hdc);
       hbmpTemp = CreateCompatibleBitmap (hdc, rin.right, rin.bottom);
       hOldBmp = SelectObject (hdctemp, hbmpTemp);
    
       SetBkColor(hdctemp, RGB(255,255,255));
       SetBkMode(hdctemp, TRANSPARENT);
       Ellipse (hdctemp, rin.left, rin.top, rin.right, rin.bottom);
    
       SelectObject(hdctemp, hOldBmp);
       DeleteDC(hdctemp);
    
    return hbmpTemp;
    }

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    527
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 527
    Points : 215
    Points
    215
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    CreateCompatibleBitmap() sur un DC nouvellement créé donne un bitmap monochrome.
    Essaie CreateDIBSection() à la place, pour créer un bitmap DIB.

    De plus, tu détruis mal ton DC: Il faut restaurer l'ancien bitmap avant:
    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
    HBITMAP MakeBmpEllipse (HDC hdc, RECT rin)
    {
    HDC hdctemp;
    HBITMAP  hbmpTemp;
    HGDIOBJ hOldBmp;
    
       hdctemp = CreateCompatibleDC (hdc);
       hbmpTemp = CreateCompatibleBitmap (hdc, rin.right, rin.bottom);
       hOldBmp = SelectObject (hdctemp, hbmpTemp);
    
       SetBkColor(hdctemp, RGB(255,255,255));
       SetBkMode(hdctemp, TRANSPARENT);
       Ellipse (hdctemp, rin.left, rin.top, rin.right, rin.bottom);
    
       SelectObject(hdctemp, hOldBmp);
       DeleteDC(hdctemp);
    
    return hbmpTemp;
    }
    J'ai modifié ma procedure et j'obtiens bien ce que je veux faire :
    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
    HBITMAP MakeBmpEllipse (HDC hdc, RECT rin)
    {
    HDC hdctemp;
    HBITMAP  hbmpTemp;
    static HPEN hpDash, hpOld;
    static HBRUSH hBrush1;
    
       hBrush1 = CreateSolidBrush (RGB(255,255,255));
       hdctemp = CreateCompatibleDC (hdc);
       hbmpTemp = CreateCompatibleBitmap (hdc, rin.right, rin.bottom);
       hpDash = CreatePen(PS_DASH, 0, RGB(0,0,0));
       SelectObject (hdctemp, hbmpTemp);
       hpOld = SelectObject(hdctemp,hpDash);
       FillRect(hdctemp, &rin, hBrush1);
       SetBkColor(hdctemp, RGB(255,255,255));
       SetBkMode(hdctemp, OPAQUE);
       Ellipse (hdctemp, rin.left, rin.top, rin.right, rin.bottom);
       SelectObject(hdctemp,hpOld);
       DeleteObject(hpDash);
       DeleteObject(hBrush1);
       DeleteDC(hdctemp);
    
    return hbmpTemp;
    }
    Mais je detruis mal de DC ?

  4. #4
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 379
    Points : 41 573
    Points
    41 573
    Par défaut
    Oui, car là encore tu le détruis sans avoir restauré l'ancien bitmap.
    De plus, tes variables n'ont aucune raison d'être static.
    Code C : 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
    HBITMAP MakeBmpEllipse (HDC hdc, RECT rin)
    {
    HDC hdctemp;
    HBITMAP  hbmpTemp, hbmpOld;
    HPEN hpDash, hpOld;
    HBRUSH hBrush1;
     
       hbmpTemp = CreateCompatibleBitmap (hdc, rin.right, rin.bottom);
       hBrush1 = CreateSolidBrush (RGB(255,255,255));
       hpDash = CreatePen(PS_DASH, 0, RGB(0,0,0));
     
       hdctemp = CreateCompatibleDC (hdc);
       hbmpOld = SelectObject (hdctemp, hbmpTemp);
       hpOld = SelectObject(hdctemp, hpDash);
     
       FillRect(hdctemp, &rin, hBrush1);
       SetBkColor(hdctemp, RGB(255,255,255));
       SetBkMode(hdctemp, OPAQUE);
       Ellipse (hdctemp, rin.left, rin.top, rin.right, rin.bottom);
     
       SelectObject(hdctemp, hpOld);
       SelectObject(hdctemp, hbmpOld);
       DeleteDC(hdctemp);
     
       DeleteObject(hpDash);
       DeleteObject(hBrush1);
     
    return hbmpTemp;
    }

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    527
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 527
    Points : 215
    Points
    215
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    Oui, car là encore tu le détruis sans avoir restauré l'ancien bitmap.
    De plus, tes variables n'ont aucune raison d'être static.
    Code C : 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
    HBITMAP MakeBmpEllipse (HDC hdc, RECT rin)
    {
    HDC hdctemp;
    HBITMAP  hbmpTemp, hbmpOld;
    HPEN hpDash, hpOld;
    HBRUSH hBrush1;
     
       hbmpTemp = CreateCompatibleBitmap (hdc, rin.right, rin.bottom);
       hBrush1 = CreateSolidBrush (RGB(255,255,255));
       hpDash = CreatePen(PS_DASH, 0, RGB(0,0,0));
     
       hdctemp = CreateCompatibleDC (hdc);
       hbmpOld = SelectObject (hdctemp, hbmpTemp);
       hpOld = SelectObject(hdctemp, hpDash);
     
       FillRect(hdctemp, &rin, hBrush1);
       SetBkColor(hdctemp, RGB(255,255,255));
       SetBkMode(hdctemp, OPAQUE);
       Ellipse (hdctemp, rin.left, rin.top, rin.right, rin.bottom);
     
       SelectObject(hdctemp, hpOld);
       SelectObject(hdctemp, hbmpOld);
       DeleteDC(hdctemp);
     
       DeleteObject(hpDash);
       DeleteObject(hBrush1);
     
    return hbmpTemp;
    }
    Pour le DC :
    DeleteDC(SelectObject (hdctemp, hbmpTemp));
    tu es d'accord, non ?
    Après pour superposer mes 2 Bitmap, un couleur et ce dernier monochrome, je passe par BitBlt ? ou une autre fonction ?
    Tu l'auras compris, je ne suis pas expert GDI ...

  6. #6
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 379
    Points : 41 573
    Points
    41 573
    Par défaut
    DeleteDC(SelectObject (hdctemp, hbmpTemp));
    tu es d'accord, non ?
    Non.

Discussions similaires

  1. Creation de bitmap
    Par buzzkaido dans le forum Windows
    Réponses: 1
    Dernier message: 04/07/2007, 18h10
  2. Creation de bitmap
    Par Pilou_m79 dans le forum MFC
    Réponses: 3
    Dernier message: 13/07/2005, 17h28
  3. creation BITMAP de fenetre
    Par daja dans le forum Windows
    Réponses: 3
    Dernier message: 10/05/2004, 18h25
  4. Creation d une clee dans la registry en VC++
    Par rico27fr dans le forum MFC
    Réponses: 4
    Dernier message: 30/05/2002, 12h36
  5. Comment faire pour créer un bitmap
    Par GliGli dans le forum C++Builder
    Réponses: 2
    Dernier message: 24/04/2002, 15h41

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