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

Langage Delphi Discussion :

TrackBar sur fonction LoadFromFile


Sujet :

Langage Delphi

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut TrackBar sur fonction LoadFromFile
    Bonjour,

    J'ai un fichier bitmap de plus de 400 Mo à charger avec la fonction Tbitmap.LoadFromFile.

    Comment activer un TTrackbar pour suivre la progression du chagement ?

    Merci à l'avance pour la réponse

    A+

  2. #2
    Membre éclairé Avatar de peter27x
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 029
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 029
    Points : 757
    Points
    757
    Par défaut
    Tu peux aller voir de ce coté là ==> TBitmap.onProgress:

    Description

    Pour certains descendants de TGraphic, OnProgress se produit lors de processus lents comme le chargement,l'enregistrement ou la transformation des données de l'image. OnProgress permet aux applications de donner à l'utilisateur une indication de l'avancement d'un processus lent.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Ok pour utiliser OnPreogress
    Merci pour cette info.
    Mais comment lier la position de progressBar avec Onprogress et comment initaialiser Max et Min du TprogressBar Avant le loadFromFile ?

  4. #4
    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
    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
    unit Unit3;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls;
     
    type
      TForm3 = class(TForm)
        ProgressBar1: TProgressBar;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        procedure DoBmpProgress(Sender: TObject; Stage: TProgressStage;
        PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
      public
        { Déclarations publiques }
      end;
     
    var
      Form3: TForm3;
     
    implementation
     
    {$R *.dfm}
     
    function ReadBitmapHeader(const FileName: string; var aBFH: BITMAPFILEHEADER; var aBIH: BITMAPINFOHEADER): boolean;
    begin
      result := false;
      with TFileStream.Create(FileName, fmOpenRead) do
      try
        read(aBFH, SizeOf(BITMAPFILEHEADER));
        read(aBIH, SizeOf(BITMAPINFOHEADER));
        result := true and (aBFH.bfType = $4D42);
      finally
        Free;
      end;
    end;
     
    var
      Bmp : TBitmap;
      Bfh : BITMAPFILEHEADER;
      Bih : BITMAPINFOHEADER;
      BmpFile : string;
     
     
    procedure TForm3.DoBmpProgress(Sender: TObject; Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
      const Msg: string);
    begin
      ProgressBar1.Position := PercentDone;
      Caption := Msg;
    end;
     
    procedure TForm3.FormCreate(Sender: TObject);
    begin
      ProgressBar1.Max := 100;
      ProgressBar1.Min := 0;
     
      BmpFile := 'C:\Dossier\Fichier.bmp';
     
      Bmp := TBitmap.Create;
      Bmp.OnProgress := DoBmpProgress;
     
      if ReadBitmapHeader(BmpFile, Bfh, Bih) then
        if MessageDlg(format('Prés pour charger le fichie bitmap %.2nKo %dx%d',[Bfh.bfSize/1024, Bih.biWidth, Bih.biHeight]),
                      mtConfirmation, [mbOk, mbAbort], 0) = mrOk then
          Bmp.LoadFromFile(BmpFile);
    end;
     
    procedure TForm3.FormDestroy(Sender: TObject);
    begin
      Bmp.Free;
    end;
     
    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!

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Ok mais problème
    La fonction de lecture de l'entête fichier fonctionne bien

    Mais la

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut suite Ok
    mais la progressbar ne se met pas à jour

  7. #7
    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
    Pas tout lu vérifier le syntaxe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    procedure TForm3.DoBmpProgress(Sender: TObject; Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
      const Msg: string);
    begin
      ProgressBar1.Position := PercentDone;
      Caption := Msg;
      Application.processmesages
    end;

  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
    et pour eviter la surcharge :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    procedure TForm3.DoBmpProgress(Sender: TObject; Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
      const Msg: string);
    begin
      ProgressBar1.Position := PercentDone;
      Caption := Msg;
      if (PercentDone mod 5) = 0 then
        Application.ProcessMessages;
    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 habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut J'ai 2 problèmes
    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
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls;
     
    type
      TForm1 = class(TForm)
        ProgressBar1: TProgressBar;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Déclarations privées }
        procedure DoBmpProgress(Sender: TObject; Stage: TProgressStage;
        PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    function ReadBitmapHeader(const FileName: string; var aBFH: BITMAPFILEHEADER; var aBIH: BITMAPINFOHEADER): boolean;
    begin
      result := false;
      with TFileStream.Create(FileName, fmOpenRead) do
      try
        read(aBFH, SizeOf(BITMAPFILEHEADER));
        read(aBIH, SizeOf(BITMAPINFOHEADER));
        result := true and (aBFH.bfType = $4D42);
      finally
        Free;
      end;
    end;
     
    var
      Bmp : TBitmap;
      Bfh : BITMAPFILEHEADER;
      Bih : BITMAPINFOHEADER;
      BmpFile : string;
     
    procedure TForm1.DoBmpProgress(Sender: TObject; Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
      const Msg: string);
    begin
      ProgressBar1.Position := PercentDone;
      Caption := Msg;
      Application.ProcessMessages;
    end;
     
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      ProgressBar1.Max := 100;
      ProgressBar1.Min := 0;
     
      BmpFile := ExtractFilePath(Application.exeName)+'CTP/OF17993wm_K.bmp';
     
      Bmp := TBitmap.Create;
      Bmp.OnProgress := DoBmpProgress;
     
      if ReadBitmapHeader(BmpFile, Bfh, Bih) then
        if MessageDlg(format('Prés pour charger le fichie bitmap %.2nKo %dx%d',[Bfh.bfSize/1024, Bih.biWidth, Bih.biHeight]),
                      mtConfirmation, [mbOk, mbAbort], 0) = mrOk then
          Bmp.LoadFromFile(BmpFile);
     
    end;
     
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Bmp.Free;
    end;
     
    end.
    Je pense avoir reproduit votre source fidèlement.
    La fiche ne s'affiche qu'après le chargement deu fichier
    Progressebar ne se met évdemment pas à jour

  10. #10
    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
    c'est normal.

    déplace le code de OnCreate dans l'evenement d'un boutton :
    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
     
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      ProgressBar1.Max := 100;
      ProgressBar1.Min := 0;
     
      Bmp := TBitmap.Create;
      Bmp.OnProgress := DoBmpProgress;
    end;
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if OpenDialog1.Execute then
        if ReadBitmapHeader(BmpFile, Bfh, Bih) then
          if MessageDlg(format('Prés pour charger le fichie bitmap %.2nKo %dx%d',[Bfh.bfSize/1024, Bih.biWidth, Bih.biHeight]),
                      mtConfirmation, [mbOk, mbAbort], 0) = mrOk then
            Bmp.LoadFromFile(BmpFile);
    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!

  11. #11
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Désolé ca ne marche toujours pas
    J'ai placé un fichier bitmap de 400 Mo dans le chemin C:\Dossier\Fichier.BMP
    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
    unit Unit3;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls;
     
    type
      TForm3 = class(TForm)
        ProgressBar1: TProgressBar;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
        procedure DoBmpProgress(Sender: TObject; Stage: TProgressStage;
        PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
      public
        { Déclarations publiques }
      end;
     
    var
      Form3: TForm3;
     
    implementation
     
    {$R *.dfm}
     
    function ReadBitmapHeader(const FileName: string; var aBFH: BITMAPFILEHEADER; var aBIH: BITMAPINFOHEADER): boolean;
    begin
      result := false;
      with TFileStream.Create(FileName, fmOpenRead) do
      try
        read(aBFH, SizeOf(BITMAPFILEHEADER));
        read(aBIH, SizeOf(BITMAPINFOHEADER));
        result := true and (aBFH.bfType = $4D42);
      finally
        Free;
      end;
    end;
     
    var
      Bmp : TBitmap;
      Bfh : BITMAPFILEHEADER;
      Bih : BITMAPINFOHEADER;
      BmpFile : string;
     
    procedure TForm3.Button1Click(Sender: TObject);
    begin
      BmpFile := 'C:\Dossier\Fichier.bmp';
        if ReadBitmapHeader(BmpFile, Bfh, Bih) then
          if MessageDlg(format('Prés pour charger le fichie bitmap %.2nKo %dx%d',[Bfh.bfSize/1024, Bih.biWidth, Bih.biHeight]),
                      mtConfirmation, [mbOk, mbAbort], 0) = mrOk then
            Bmp.LoadFromFile(BmpFile);
    end;
     
    procedure TForm3.DoBmpProgress(Sender: TObject; Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
      const Msg: string);
    begin
      ProgressBar1.Position := PercentDone;
      Caption := Msg;
      Application.ProcessMessages;
    end;
     
    procedure TForm3.FormCreate(Sender: TObject);
    begin
      ProgressBar1.Max := 100;
      ProgressBar1.Min := 0;
      Bmp := TBitmap.Create;
      Bmp.OnProgress := DoBmpProgress;
    end;
     
    procedure TForm3.FormDestroy(Sender: TObject);
    begin
      Bmp.Free;
    end;
     
    end.
    Le progressbar reste vierge
    Mieux, en plaçant un point d'arret sur la ligne Caption := Msg; dans TForm3.DoBmpProgress Je m'aperçois que doBmpProgress n'est jamais appelée

  12. #12
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut J'ai ajouté un TImage pour vérifier le chargement
    avec les deux procédures :
    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
    // retourne dans Wc et Hc les dimensions de BMP réduite pour s'afficher dans
    // un Timage de dimension Wa, Ha
    procedure ImageDimCible( BMP: TBitmap; Wa,Ha: Integer; var Wc,Hc: integer);
    var
      Hi,Wi : Integer;
      Ri,Ra : Double;
    begin
      // Dimensionnement proportionnel de l'image Bitmap
      Wi := BMP.Width;  // Largeur Bitmap initiale
      Hi := BMP.Height; // Hauteur Bitmap initiale
      Ri := Wi/Hi;         // Rapport Largeur/Hauteur initiale
      Ra := Wa/Ha;         // Rapport Largeur/Hauteur allouée
      if Ri>Ra then
      begin
        Hc := round(Hi*Wa/Wi);
        Wc := Wa;
      end
      else
      begin
        Hc := Ha;
        Wc := round(Wi*Ha/Hi);
      end;
    end;
     
    procedure DisplayImage( ImageShooted: TImage; BMPSource:TBitmap);
    var
      W,H,Wc,Hc,x1,x2,y1,y2: Integer;
      IRect,ImgRect: TRect;
    begin
      ImageShooted.Canvas.Pen.Color:= clWhite;
      IRect:= Rect(0,0,ImageShooted.Width,ImageShooted.Height);
      ImageShooted.Canvas.FillRect(IRect);
      // Dimensionnement proportionnel de l'image
      W:= ImageShooted.Width;
      H:= ImageShooted.Height;
      ImageDimCible( BMPSource,W,H,Wc,Hc);
      With ImageShooted.canvas do
      begin
        x1:= (W-Wc) div 2;
        y1:= (H-Hc) div 2;
        x2:= x1+Wc;
        y2:= y1+Hc;
        ImgRect:= Rect(x1,y1,x2,y2);
        StretchDraw(ImgRect,BMPSource);
      end;
    end;
    et en remplaçant la procedure Button1Click par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    procedure TForm3.Button1Click(Sender: TObject);
    begin
      BmpFile := 'C:\Dossier\Fichier.bmp';
        if ReadBitmapHeader(BmpFile, Bfh, Bih) then
          if MessageDlg(format('Prés pour charger le fichie bitmap %.2nKo %dx%d',[Bfh.bfSize/1024, Bih.biWidth, Bih.biHeight]),
                      mtConfirmation, [mbOk, mbAbort], 0) = mrOk then
          begin
            Bmp.LoadFromFile(BmpFile);
            DisplayImage(Image1,BMP);
          end;
    end;
    L'image s'affiche dans Image1, ce qui prouve que le bitmap s'est correctement chargé

  13. #13
    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
    l'événement onProgress ne fonctionnera pas il n'est pas utiliser en interne
    pour l'affichage de l'image il y a surement une erreur dans l'entête du fichier bmp

  14. #14
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut En interne de quoi ?
    Qu'entendez-vous par En interne ?

  15. #15
    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
    Qu'entendez-vous par En interne ?
    tu ne peux pas l'utiliser
    supprime tout les ligne contenant Bmp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if OpenDialog1.Execute then
        if ReadBitmapHeader(BmpFile, Bfh, Bih) then
          if MessageDlg(format('Prés pour charger le fichie bitmap %.2nKo %dx%d',[Bfh.bfSize/1024, Bih.biWidth, Bih.biHeight]),
                      mtConfirmation, [mbOk, mbAbort], 0) = mrOk then
            Image1.Picture.LoadFromFile(BmpFile);
    end;

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

Discussions similaires

  1. Réponses: 10
    Dernier message: 03/02/2005, 13h09
  2. Réponses: 5
    Dernier message: 12/01/2005, 20h58
  3. pointeurs sur fonction en C++
    Par cemoi dans le forum C++
    Réponses: 7
    Dernier message: 29/11/2004, 13h19
  4. [langage] Pointeur sur fonction
    Par Fanch.g dans le forum Langage
    Réponses: 2
    Dernier message: 02/10/2004, 10h43
  5. Declaration de fonction retournant un pointeur sur fonction
    Par pseudokifaitladifférence dans le forum C
    Réponses: 5
    Dernier message: 11/08/2003, 19h37

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