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

DirectX Discussion :

[DirectX]Incrustation de texte


Sujet :

DirectX

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2002
    Messages : 45
    Par défaut [DirectX]Incrustation de texte
    Bonjour,

    Mon probleme est le suivant, je joue une video, et j'aimerai pouvoir incruster dessus plusieurs textes predefinis a des positions predefinies aussi. (par exemple le nom de la video en haut et la date courant en bas a droite).
    J'ai trouve cet exemple [lien] qui fonction quand je n'ai qu'un seul texte a afficher.
    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
    HRESULT BlendText(HWND hwndApp, TCHAR *szNewText)
    {
    LONG cx, cy;
        HRESULT hr;
     
        // Read the default video size
        hr = pWC->GetNativeVideoSize(&cx, &cy, NULL, NULL);
        if (FAILED(hr))
        {
            Msg(TEXT("GetNativeVideoSize FAILED!  hr=0x%x\r\n"), hr);
            return hr;
        }
     
        // Create a device context compatible with the current window
        HDC hdc = GetDC(hwndApp);
        HDC hdcBmp = CreateCompatibleDC(hdc);
     
        // Write with a known font by selecting it into our HDC
        HFONT hOldFont = (HFONT) SelectObject(hdcBmp, g_hFont);
     
        // Determine the length of the string, then determine the
        // dimensions (in pixels) of the character string using the
        // currently selected font.  These dimensions are used to create
        // a bitmap below.
        int nLength, nTextBmpWidth, nTextBmpHeight;
        SIZE sz={0};
        nLength = _tcslen(szNewText);
        GetTextExtentPoint32(hdcBmp, szNewText, nLength, &sz);
        nTextBmpHeight = sz.cy;
        nTextBmpWidth  = sz.cx;
     
        // Create a new bitmap that is compatible with the current window
        HBITMAP hbm = CreateCompatibleBitmap(hdc, nTextBmpWidth, nTextBmpHeight);
        ReleaseDC(hwndApp, hdc);
     
        // Select our bitmap into the device context and save the old one
        BITMAP bm;
        HBITMAP hbmOld;
        GetObject(hbm, sizeof(bm), &bm);
        hbmOld = (HBITMAP)SelectObject(hdcBmp, hbm);
     
        // Set initial bitmap settings
        RECT rcText;
        SetRect(&rcText, 0, 0, nTextBmpWidth, nTextBmpHeight);
        SetBkColor(hdcBmp, RGB(255, 255, 255)); // Pure white background
        SetTextColor(hdcBmp, g_rgbColors);   
     
        // Draw the requested text string onto the bitmap
        TextOut(hdcBmp, 0, 0, szNewText, nLength);
     
        // Configure the VMR's bitmap structure
        VMRALPHABITMAP bmpInfo;
        ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
        bmpInfo.dwFlags = VMRBITMAP_HDC;
        bmpInfo.hdc = hdcBmp;  // DC which has selected our bitmap
     
        // Remember the width of this new bitmap
        g_nImageWidth = bm.bmWidth;
     
        // Save the ratio of the bitmap's width to the width of the video file.
        // This value is used to reposition the bitmap in composition space.
        g_fBitmapCompWidth = (float)g_nImageWidth / (float)cx;
     
        // Display the bitmap in the bottom right corner.
        // rSrc specifies the source rectangle in the GDI device context 
        // rDest specifies the destination rectangle in composition space (0.0f to 1.0f)
        bmpInfo.rDest.left = 0.0f + X_EDGE_BUFFER;
        bmpInfo.rDest.right = 1.0f - X_EDGE_BUFFER;
        bmpInfo.rDest.top = (float)(cy - bm.bmHeight) / (float)cy - Y_EDGE_BUFFER;
        bmpInfo.rDest.bottom = 1.0f - Y_EDGE_BUFFER;
        bmpInfo.rSrc = rcText;
     
        // Transparency value 1.0 is opaque, 0.0 is transparent.
        bmpInfo.fAlpha = TRANSPARENCY_VALUE;
     
        // Set the COLORREF so that the bitmap outline will be transparent
        SetColorRef(bmpInfo);
     
        // Give the bitmap to the VMR for display
        hr = pBMP->SetAlphaBitmap(&bmpInfo);
        if (FAILED(hr))
            Msg(TEXT("SetAlphaBitmap FAILED!  hr=0x%x\r\n\r\n")
                TEXT("NOTE: Your display must be configured for 32-bit color depth\r\n")
                TEXT("for this sample to display alpha-blended text."), hr);
     
        // Select the initial objects back into our device context
        DeleteObject(SelectObject(hdcBmp, hbmOld));
        SelectObject(hdc, hOldFont);
     
        // Clean up resources
        DeleteObject(hbm);
        DeleteDC(hdcBmp);
     
        return hr;}
    Si je rappelle une seconde fois cette fonction avec un 2nd texte, le precedent texte est supprimé.

    Auriez vous des pistes pour m'aider a faire cela ?

    Merci

  2. #2
    J&B
    J&B est déconnecté
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 26
    Par défaut
    Il est normal que le texte precedent est suprimé car cette fonction enregistre l'ancienne image mais ne la recopie pas.
    Peux être en ecrivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    bmpInfo.hdc = hdcOld;
    pBMP->SetAlphaBitmap(&bmpInfo);
    avant le DeleteObject

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    80
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 80
    Par défaut
    moi jai un pb , je recoi le message, "Your display must be configured for 32-bit color depth" car SetAlphaBitmap échoue avec lerreur : 80040227 qui correspond à
    Description: The operation could not be performed because the filter is in the wrong state.

    Une idée ?

    (jai vérifier, dans les propriété daffichage, je suis en 1280*1024 en 32bit (carte ati radeon 9800 pro) donc je pense que le pb vient pas du color depth)

    Et je ne comprend pas où g_fBitmapCompWidth est utilisé ?

    merci

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    80
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 80
    Par défaut
    Pour faire disparaitre le text (la bitmap incrusté), il faut faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    VMRALPHABITMAP bmpInfo;
    ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
    bmpInfo.dwFlags = VMRBITMAP_DISABLE  ;
    pBitmapMixer->UpdateAlphaBitmapParameters(&bmpInfo);
    ou bien faire exactement comme il est dit dans la doc de directshow:
    "To remove the bitmap, set the VMRBITMAP_DISABLE flag in the VMRALPHABITMAP structure and call SetAlphaBitmap again." mais faire un update est plus légé je pense.

Discussions similaires

  1. Incruster du texte dans une image
    Par Taiby dans le forum Images
    Réponses: 3
    Dernier message: 12/12/2014, 13h21
  2. [Débutant] Incruster un texte dans une image jpeg
    Par choupinou22 dans le forum VB.NET
    Réponses: 5
    Dernier message: 21/08/2013, 14h01
  3. incruster un texte sur une image
    Par rigolman dans le forum Langage
    Réponses: 24
    Dernier message: 02/06/2011, 14h25
  4. Réponses: 4
    Dernier message: 19/07/2007, 14h59
  5. incruster du texte dans border-top
    Par nicerico dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 18/11/2006, 00h47

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