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

Contribuez Delphi Discussion :

Dessiner le texte d'un richedit sur une image


Sujet :

Contribuez Delphi

  1. #1
    Membre éprouvé
    Avatar de Montor
    Homme Profil pro
    Autre
    Inscrit en
    Avril 2008
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Avril 2008
    Messages : 879
    Points : 963
    Points
    963
    Par défaut Dessiner le texte d'un richedit sur une image
    Tester sous Delphi7
    Voici ce morceau de code qui permet dessiner le texte d'un richedit sur une image (.bmp)le code n'est pas très élégant mais reste utilisable
    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
     
    Uses richedit;
    procedure PrintRichedit(ARichEdit:TRichEdit;ACanvas:TCanvas;SLine:Integer=0;ELine:Integer=-1);
    var
      CharRange: TFormatRange;
      sBitmap:TBitmap;
      SPos,EPos:Integer;
    begin
        sBitmap:=TBitmap.Create;
        FillChar(CharRange, SizeOf(TFormatRange), 0);
     try
      with ARichEdit do
        begin
          sBitmap.Height:=ClientHeight;
          sBitmap.Width:=ClientWidth;
          sBitmap.Canvas.Brush.Color:=Color;
          sBitmap.Canvas.FillRect(ClientRect);
          if(ELine<>-1) then inc(ELine);
          SPos:=Perform(EM_LINEINDEX,SLine,0);
          EPos:=Perform(EM_LINEINDEX,ELine,0);
      with sBitmap.Canvas, CharRange do
        begin
          chrg.cpMin:=0;
          chrg.cpMax := -1;
          if(((SPos<>-1)and (EPos<>-1))and (SPos <= EPos)) then
          begin
            chrg.cpMin:=SPos;
            chrg.cpMax:=EPos;
          end;
          hdc := Handle;
          rc:=ClientRect;
          hdcTarget := Handle;
          rc.left:=0;
          rc.top :=0;
          rc.right :=MulDiv(rc.right,1440,GetDeviceCaps(Handle, LOGPIXELSX));
          rc.bottom :=MulDiv(rc.bottom,1440,GetDeviceCaps(Handle, LOGPIXELSY));
          rcPage := rc;
        end;
          Perform(EM_FORMATRANGE, 0, 0);
          Perform(EM_FORMATRANGE, 1, Longint(@CharRange));
          Perform(EM_FORMATRANGE, 0, 0);
          TransparentBlt(ACanvas.Handle,2,2,ClientWidth,ClientHeight,
          sBitmap.Canvas.Handle,0,0,ClientWidth,ClientHeight,ColorToRgb(Color));
      end;
     finally
        sBitmap.Free;
     end;
    end;
    Utilisation
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      PrintRichedit(RichEdit1,Image1.Canvas,0,10);
      Image1.Invalidate;
    end;
    le toisième et quatrième paramètre sont les début et fin des lignes sélectionnées mais attention à la property WordWrap .

  2. #2
    Membre éprouvé
    Avatar de Montor
    Homme Profil pro
    Autre
    Inscrit en
    Avril 2008
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Avril 2008
    Messages : 879
    Points : 963
    Points
    963
    Par défaut
    Voici une pseudo infobulle Office 2007
    J'ai redéfini La fonction GradientFill sous Delphi7 qui ne marche pas est défini comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    function GradientFill(DC: HDC; var Vertex: TTriVertex; NumVertex: ULONG; Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall;
    Sous Delphi 2006
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    function GradientFill(DC: HDC; Vertex: PTriVertex; NumVertex: ULONG; Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall;
    Mais pas seulement la fonction GradientFill qu’il faut la redéfinir mais aussi COLOR16 déclarer Shortint sous Delphi7 est Word sous Delphi 2006 est qui va impliquer touts les type définies qu'il le utilise dans mon cas c'est TTriVertex
    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
    unit PersoHint;
    interface
    uses
      Windows, Messages, SysUtils,Classes, Graphics, Controls, Forms;
    type
      TPersoHintWindow = class(THintWindow)
      private
        procedure drw;
      protected
        procedure CreateParams(var Params: TCreateParams);override;
        procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
        procedure Paint; override;
      public
        constructor Create(AOwner: TComponent); override;
      end;
    var
      HintStartColor:TColor;
      HintEndColor:TColor;
    implementation
    type
        COLOR16 = Word;
        TTriVertex = packed record
          x: Longint;
          y: Longint;
          Red: COLOR16;
          Green: COLOR16;
          Blue: COLOR16;
          Alpha: COLOR16;
        end;
    function GradientFill(DC: HDC; Vertex: PTriVertex; NumVertex: ULONG; Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall;external 'msimg32.dll';
     
    constructor TPersoHintWindow.Create(AOwner: TComponent);
    begin
       inherited Create(AOwner);
       HintStartColor:=clWhite;
       HintEndColor:=$00FFDACA;
    end;
     
    procedure TPersoHintWindow.drw;
     procedure Cplt(Var AVertex:TTriVertex;AColor:TColor);
      begin
         AVertex.Red:=GetRValue(AColor) shl 8;
         AVertex.Green:=GetGValue(AColor)shl 8;
         AVertex.Blue:=GetBValue(AColor)shl 8;
         AVertex.Alpha:=0;
      end;
    var
    vertex:array[0..1] of TTriVertex;
    gTri    :TGradientRect;
    begin
      with ClientRect do
       begin
        Cplt(vertex[0],HintStartColor);
        vertex[0].X:=Left;
        vertex[0].Y:=Top;
        Cplt(vertex[1],HintEndColor);
        vertex[1].X:=Right-Left;
        vertex[1].Y:=Bottom-Top;
     end;
      gTri.UpperLeft := 0;
      gTri.LowerRight := 1;
      GradientFill(Canvas.handle,@vertex , 2, @gTri, 1, GRADIENT_FILL_RECT_V);
    end;
     
    procedure TPersoHintWindow.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      with Params do
        Style := WS_POPUP  and not WS_BORDER ;
    end;
     
    procedure TPersoHintWindow.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
    begin
     Msg.Result :=1;
    end;
     
    procedure TPersoHintWindow.Paint;
    begin
      drw;
      inherited;
    end;
     
     initialization
     HintWindowClass := TPersoHintWindow;
    end.

  3. #3
    Rédacteur
    Avatar de Pedro
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    5 411
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 5 411
    Points : 8 078
    Points
    8 078
    Par défaut
    Merci pour ta participation
    Pedro
    Aucune réponse aux sollicitations techniques par MP

    Faut pas attendre d'en avoir besoin pour s'en servir... (Lucien Stéphane)

    Les pages Source C'est bon. Mangez-en!
    Le défi Delphi
    Règles du forum - FAQ Delphi - Pensez au chtit
    Aéroclub Bastia Saint-Exupéry

Discussions similaires

  1. Dessin d'un text sur une image
    Par grisby007 dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 18/10/2011, 16h28
  2. Champs input type="text" n'apparait pas sur une image
    Par sofuzion dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 04/06/2009, 09h16
  3. Aligner du texte à gauche et à droite sur une même ligne ?
    Par pontus21 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 12/04/2005, 11h25
  4. [HTML]Peut-on écrire un texte sur une image ?
    Par flogreg dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 28/02/2005, 17h24
  5. [Servlet] [Image] Dessiner sur une image
    Par gaia_dev dans le forum 2D
    Réponses: 5
    Dernier message: 01/09/2004, 17h11

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