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

 Delphi Discussion :

Image plusieurs fois dans un TImage


Sujet :

Delphi

  1. #1
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut Image plusieurs fois dans un TImage
    Bonjour,

    Est il possible (peut être avec un autre objet que TImage) de charger une image et que celle ci remplisse le canvas en gardant sa proportionnalité, donc avec plusieurs fois la même image
    Un peu comme dans les pages Web, le remplissage du fond
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <body
     style="background-image: url(file:///F:/Boutons%20&amp;%20images/Autre/AMPOLAS2.BMP);">
    <br>
    </body>
    la page est remplit de petites ampoules

    Si dans mon objet je dois afficher 4 fois l'image pour remplire la surface du canvas, je ne voudrais pas devoir la charger 4 fois

    J'espère avoir été claire (j'en suis pas sure)

    merci d'avance

  2. #2
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Il suffit de mettre la propriété stretch à true dans ton Timage après avoir chargé l'image dans picture.

    cordialement

  3. #3
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    stretch, va mettre l'image de la taille du canvas et ce que je veux c'est avoir plusieurs fois l'image dans le canvas de manière à le remplire

  4. #4
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    tu fais plusieurs copyrect dans ton canvas....

    ou stretchdraw... encore mieux

  5. #5
    Membre chevronné

    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2009
    Messages
    935
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Aveyron (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2009
    Messages : 935
    Points : 1 765
    Points
    1 765
    Par défaut
    Salut

    Si tu as besoin d'afficher plein de fois un motif, le plus simple est surement la DrawGrid ... Ensuite, faut voir tes besoins. Si c'est seulement pour une image de fond ...

    Bonne chance

  6. #6
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    avec strechdraw, ce n'est pas bien compliqué...

    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
     
    procedure TForm1.FormCreate(Sender: TObject);
    var i:word;
    begin
    image1.SetBounds(100,100,400,400);
    for i:=2 to 5 do (findComponent('image'+inttostr(i)) as Timage).visible:=false;
     
     with image1.canvas do
       begin
          StretchDraw(rect(0,0,200,200),image2.Picture.Graphic);
          StretchDraw(rect(200,0,400,200),image3.Picture.Graphic);
          StretchDraw(rect(0,200,200,400),image4.Picture.Graphic);
          StretchDraw(rect(200,200,400,400),image5.Picture.Graphic);
        end;
    end;
     
    un premier Timage de 400x400 pixels avec visible à true.
     
    4 autres Timage à visible false dans lequel tu charges tes photos.
    Ensuite on affiche tout dans des vignettes de 200x200 pixels par exemple  dans le premier Timage
    c'est simple...

  7. #7
    Membre chevronné

    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2009
    Messages
    935
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Aveyron (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2009
    Messages : 935
    Points : 1 765
    Points
    1 765
    Par défaut
    C'est vrai, mais attention :
    en gardant sa proportionnalité
    Donc il faut aussi récuperer la taille de l'image d'origine, et soit utiliser StrechDraw, soit simplement utiliser Draw si l'image doit avoir la meme taille que celle d'origine.

    Pourquoi ya-t-il tant de TImage dans ton code ? A moins que ce ne soit un simple exemple d'utilisation du strechdraw

  8. #8
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    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
    procedure DrawBitmapMosaic(BMP: TBitmap; Canvas: TCanvas);
    var W, H, X, Y: integer;
    begin
      W := Canvas.ClipRect.Right - Canvas.ClipRect.Left;
      H := Canvas.ClipRect.Bottom - Canvas.ClipRect.Top;
      Y := 0;
      repeat
        X := 0;
        repeat
          Canvas.Draw(X, Y, BMP);
          inc(X, BMP.Width{-1});
        until X <= W;
        inc(Y, BMP.Height{-1});
      until Y <= H;
    end;
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  9. #9
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Pourquoi ya-t-il tant de TImage dans ton code ? A moins que ce ne soit un simple exemple d'utilisation du strechdraw
    Tout simplement pour éviter de me retrouver avec des bitmaps à créer avec les lesquels je devrai faire des loadfromfile pour charger mes images avec le chemin...

    ici les Timage me servent uniquement et simplement à charger les photos et récupérer directement des TGraphic.
    D'ailleurs, je les mets à visible false pour cet unique but.

    On peut utiliser aussi un TImagelist et faire des draw ou des copyrect avec rectsource et rectdestination... ce qui permet de garder les proportions d'origine...

    Sinon pour un grand nombre de photos, rien n'empêche de faire une boucle avec stretchdraw ou copyrect en paramétrant les rects avec l'indice de la boucle. (ce qui permettrait en une ligne de dessiner toute une série d'images...

    des solutions, il y en a plein... une drawgrid aussi ...

  10. #10
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    merci pour votre aide

    Je vais tester la solution de Dr.Who.

    Il faut savoir que mon programme doit pouvoir gérer plus d'une centaine d'objets TImages en même temps (pas tous avec des images) c'est pour cela que je cherche la rapidité d'affichage

    Merci encore et je vous tiens au courant

  11. #11
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    TPicture!
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  12. #12
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Je vais tester la solution de Dr.Who.

    Il faut savoir que mon programme doit pouvoir gérer plus d'une centaine d'objets TImages en même temps (pas tous avec des images) c'est pour cela que je cherche la rapidité d'affichage
    Ben justement, si tu ne veux pas répéter toujours la même image, la boucle avec toujours le même bmp ne va pas te convenir telle quelle lol.
    Il va falloir la bidouiller en utilisant getbitmap avec un Timagelist pour charger l'image voulue ( ou pas )dans bmp suivant l'indice dans ta boucle.
    Il te sera nécessaire de revenir sur la procedure...en la complétant.

    C'est la meilleure solution...

  13. #13
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 747
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 747
    Points : 13 313
    Points
    13 313
    Par défaut
    Travailler avec ClipRect est correct, mais son implémentation ne l'est pas ! En fait ça ne fonctionnera qu'au premier appel si la fiche (ou le contrôle) doit être entièrement repeinte.

    ClipRect est un rectangle récupéré depuis le GDI spécifiant la zone devant être réaffichée; qui ne correspond pas forcement au point 0/0 (X/Y).

    ps: J'opterais pour de simple CopyRect .

  14. #14
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    J'en reste que je suis obligé de faire du "copier / coller" de mon image et qu'il n'y a pas d'objet réalisant cette opération de façon automatique

    La méthode "copier / coller" m'oblige à limiter les formats d'images et ou de les prévoirs tous pour les transformer en BMP (pas de Gif annimé).

    Merci pour votre aide, je vais travailler avec tous ce que vous m'avez donné

    Merci

  15. #15
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    Bonjour,

    Je travail sur un objet permettant de réaliser simplement cette fonction


  16. #16
    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
    stretch, va mettre l'image de la taille du canvas et ce que je veux c'est avoir plusieurs fois l'image dans le canvas de manière à le remplire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Canvas.Brush.bitmap:=mYBITMAP

  17. #17
    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
    juste il faut ajouter
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Canvas.Brush.Bitmap:=image1.Picture.Bitmap;
      Canvas.FillRect(Canvas.ClipRect);
    end;

  18. #18
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    Voici l'objet en question

    Si vous voulez le tester

    Problèmes :
    1. quand on redimensionne l'objet la mosaïque disparait
    2. Quand je supprime la mosaïque elle peut rester dans les zone sans image


    Si vous avez des améliorations ...

    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
    { ****************************************************************** }
    {                                                                    }
    {   VCL component TMosaic                                            }
    {                                                                    }
    {   Code generated by Component Create for Delphi                    }
    {                                                                    }
    {   Generated from source file c:\documents and settings\admin\mes documents\delphi\objets\mosaic.cd }
    {   on 1 Jan 2002 at 3:03                                            }
    {                                                                    }
    {   Copyright © 2010 by Deconchat                                    }
    {                                                                    }
    { ****************************************************************** }
     
    unit Mosaic;
     
    interface
     
    uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls, 
         Forms, Graphics, Extctrls, Jpeg, Dialogs;
     
    { Unit-wide declarations }
    type TPublicGraphicControl=class(TGraphicControl);
     
    { var }
         { . . . }
     
    type
      TMosaic = class(TImage)
        private
          { Private fields of TMosaic }
            { Storage for property Mosaic }
            FMosaic : Boolean;
     
          { Private methods of TMosaic }
            { Method to set variable and property values and create objects }
            procedure AutoInitialize;
            { Method to free any objects created by AutoInitialize }
            procedure AutoDestroy;
            { Read method for property Mosaic }
            function GetMosaic : Boolean;
            { Write method for property Mosaic }
            procedure SetMosaic(Value : Boolean);
            procedure WMSize(var Message: TWMSize); message WM_SIZE;
     
        protected
          { Protected fields of TMosaic }
            Mosaic_faite : Boolean;
     
          { Protected methods of TMosaic }
            procedure Loaded; override;
            procedure Paint; override;
     
        public
          { Public fields and properties of TMosaic }
     
          { Public methods of TMosaic }
            constructor Create(AOwner: TComponent); override;
            destructor Destroy; override;
     
        published
          { Published properties of TMosaic }
            property OnDblClick;
            property OnDragDrop;
            property OnMouseDown;
            property OnMouseMove;
            property OnMouseUp;
            property Mosaic : Boolean read GetMosaic write SetMosaic default False;
     
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
         { Register TMosaic with Deconchat as its
           default page on the Delphi component palette }
         RegisterComponents('Deconchat', [TMosaic]);
    end;
     
    { Method to set variable and property values and create objects }
    procedure TMosaic.AutoInitialize;
    begin
         Mosaic_faite := False;
         FMosaic := False;
    end; { of AutoInitialize }
     
    { Method to free any objects created by AutoInitialize }
    procedure TMosaic.AutoDestroy;
    begin
         { No objects from AutoInitialize to free }
    end; { of AutoDestroy }
     
    { Read method for property Mosaic }
    function TMosaic.GetMosaic : Boolean;
    begin
         Result := FMosaic;
    end;
     
    { Write method for property Mosaic }
    procedure TMosaic.SetMosaic(Value : Boolean);
    var change : boolean;
    begin
        change:=fmosaic;
         FMosaic := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
         Mosaic_faite:=change=fmosaic;
         paint;
    end;
     
    constructor TMosaic.Create(AOwner: TComponent);
    begin
         { Call the Create method of the parent class }
         inherited Create(AOwner);
     
         { AutoInitialize sets the initial values of variables and      }
         { properties; also, it creates objects for properties of       }
         { standard Delphi object types (e.g., TFont, TTimer,           }
         { TPicture) and for any variables marked as objects.           }
         { AutoInitialize method is generated by Component Create.      }
         AutoInitialize;
     
         { Code to perform other tasks when the component is created }
     
    end;
     
    destructor TMosaic.Destroy;
    begin
         { AutoDestroy, which is generated by Component Create, frees any   }
         { objects created by AutoInitialize.                               }
         AutoDestroy;
     
         { Here, free any other dynamic objects that the component methods  }
         { created but have not yet freed.  Also perform any other clean-up }
         { operations needed before the component is destroyed.             }
     
         { Last, free the component by calling the Destroy method of the    }
         { parent class.                                                    }
         inherited Destroy;
    end;
     
    procedure TMosaic.Loaded;
    begin
         inherited Loaded;
     
         { Perform any component setup that depends on the property
           values having been set }
        Mosaic_faite:=false;
    end;
     
    procedure TMosaic.Paint;
    Var bmp : TBitmap;
        n, max : integer;
    begin
         { Make this component look like its parent component by calling
           its parent's Paint method. }
         inherited Paint;
     
         { To change the appearance of the component, use the methods
           supplied by the component's Canvas property (which is of
           type TCanvas).  For example, }
     
    if (fmosaic) then
       begin  // Mosaïc à faire
         if (not(Mosaic_faite)) then
             begin
               bmp:= TBitmap.Create;
               try
                 bmp.width:=Picture.Graphic.Width;
                 bmp.Height:=Picture.Graphic.Height;
                 bmp.Canvas.draw(0,0,picture.Graphic);
     
                 if width/bmp.width>height/bmp.height then
                    begin
                      max:=trunc(bmp.width*height/bmp.height);
                      for n:=0 to trunc(width/max) do
                          begin
                            TPublicGraphicControl(self).Canvas.StretchDraw(rect(n*max,0,(n+1)*max,height),bmp);
                          end;
                    end                               else
                    begin
                      max:=trunc(bmp.height*width/bmp.width);
                      for n:=0 to trunc(height/max) do
                          begin
                            TPublicGraphicControl(self).Canvas.StretchDraw(rect(0,n*max,width,(n+1)*max),bmp);
                          end;
                    end;
     
               finally
                 bmp.free
               end;
               Mosaic_faite:=true;    
             end;
       end       else
       begin  // pas de mosaïc
         With TPublicGraphicControl(self).Canvas do
              begin
                Pen.Width:=1;
                Pen.Color := clRed;
                Pen.Style:=psclear;
                Brush.style := bsclear;
                Rectangle(0,0,Width+1,Height+1);
              end;
       end;  
    end;
     
    procedure TMosaic.WMSize(var Message: TWMSize);
    var
         W, H: Integer;
    begin
         Mosaic_faite:=false;
         inherited;
     
         { Copy the new width and height of the component
           so we can use SetBounds to change both at once }
         W := Width;
         H := Height;
     
         { Code to check and adjust W and H }
     
         { Update the component size if we adjusted W or H }
         if (W <> Width) or (H <> Height) then
            inherited SetBounds(Left, Top, W, H);
     
         { Code to update dimensions of any owned sub-components
           by reading their Height and Width properties and updating
           via their SetBounds methods }
     
         Message.Result := 0;
         paint; 
    end;
     
     
    end.

  19. #19
    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
    Pour un premier prototypee
    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
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Buttons, ExtCtrls;
     
     TImageRp =class(TImage)
      private
        FAutoArrange: boolean;
        FBitmap :TBitmap;
        procedure SetAutoArrange(const Value: boolean);
        function GetHeight: Integer;
        function GetWidth: Integer;
        procedure SetHeight(const Value: Integer);
        procedure SetWidth(const Value: Integer);
     protected
        procedure Paint();override;
        procedure PictureChange(Sender:TObject);
     public
       constructor Create(AOwner:TComponent);override;
       destructor Destroy();override;
     published
        property AutoArrange :boolean read FAutoArrange write SetAutoArrange;
        property Width: Integer read GetWidth write SetWidth;
        property Height: Integer read GetHeight write SetHeight;
     end;
     
    implementation
     uses jpeg;{ne pas retirer}
    type
     TGC= class(TGraphicControl)
     public
       property Canvas;
     end;
    { TImageEx }
     
    constructor TImageRp.Create(AOwner: TComponent);
    begin
      inherited;
      Picture.OnChange := PictureChange;
      AutoArrange := true;
    end;
     
    destructor TImageRp.Destroy;
    begin
      FBitmap.Free;
      inherited;
    end;
     
    function TImageRp.GetHeight: Integer;
    begin
       result:=inherited Height;
    end;
     
    function TImageRp.GetWidth: Integer;
    begin
      result:=inherited Width;
    end;
     
    procedure TImageRp.SetHeight(const Value: Integer);
    begin
       inherited Height:= Value;
       if Assigned(FBitmap)then
          FBitmap.Height :=Height;
    end;
     
    procedure TImageRp.SetWidth(const Value: Integer);
    begin
       inherited Width:= Value;
       if Assigned(FBitmap)then
          FBitmap.Width  :=Width;
    end;
     
    procedure TImageRp.Paint;
    begin
       if FAutoArrange then
        TGC(Self).Canvas.draw(0,0,FBitmap)
       else
         inherited;
    end;
     
    procedure TImageRp.PictureChange(Sender: TObject);
     var
     bmp:TBitmap;
    begin
       if not FAutoArrange then Exit;
       bmp:=TBitmap.Create;
       try
          FBitmap.Width  :=Width;
          FBitmap.Height :=Height;
          if Assigned(Picture.Graphic) then
          begin
              bmp.Width:=Picture.Graphic.Width;
              bmp.Height:=Picture.Graphic.Height;
              bmp.Canvas.Draw(0,0,Picture.Graphic);
              FBitmap.Canvas.Brush.Bitmap:=bmp;
          end;
          FBitmap.Canvas.FillRect(Rect(0,0,Width-1,Height-1));
       finally
         bmp.Free();
       end;
     
    end;
     
    procedure TImageRp.SetAutoArrange(const Value: boolean);
    begin
      if  FAutoArrange = Value then Exit;
      FAutoArrange := Value;
      if Value then
      begin
       if not Assigned(FBitmap)then
           FBitmap :=TBitmap.Create;
      end
         else FreeAndNil(FBitmap);
      invalidate;
    end;

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 21/11/2007, 12h19
  2. [GD] Redimension d'image - plusieurs erreurs dans mon script
    Par Henry9 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 18/02/2007, 10h58
  3. Sous-requête excutée plusieurs fois dans une requête
    Par sheridan31 dans le forum Oracle
    Réponses: 8
    Dernier message: 03/07/2006, 16h18
  4. Réponses: 2
    Dernier message: 14/06/2006, 08h53
  5. Image en mosaique dans un TImage
    Par Maitre Dragon dans le forum C++Builder
    Réponses: 6
    Dernier message: 31/07/2004, 13h18

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