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

C++Builder Discussion :

Probleme de buffer


Sujet :

C++Builder

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 10
    Par d�faut Probleme de buffer
    bonjour,

    Voila j'ai effectuer une reception d'image avec clientsocket et j'affiche cette image ares l'avoir recu, mais j'ai un probleme avec le buffer, kan je recoi la 1ere image elle fait 23Ko , puis kan je recoi la 2eme image(ou la meme) elle fai 46Ko et ainsi de suite, sa augmente et j'ai un message derreur , donc je voudrais savoir comment effac� le buffer une fois l'image afficher, voici mon code :

    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
    //---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    FILE *fp;
    int n = 0;
     
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
          TCustomWinSocket *Socket)
    {
     char buf[15000];
       n=Socket->ReceiveBuf(buf,15000);
     
       fp = fopen("test.bmp","a+b");
       fwrite(buf, 1 , n , fp) ;
       fclose(fp) ; 
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    Form1->Image1->Picture->LoadFromFile("test.bmp");
    }
    //---------------------------------------------------------------------------

  2. #2
    CGi
    CGi est actuellement connect�
    Expert confirm�
    Avatar de CGi
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    1 061
    D�tails du profil
    Informations personnelles :
    Localisation : France, Allier (Auvergne)

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 061
    Par d�faut
    Ton probl�me doit venir de fopen car ton image suivante
    est charg�e dans le m�me fichier,
    et avec l'option "a" � fopen il ajoute ton buffer � la fin du fichier d�j� existant.
    Donc a chaque nouvelle image il faudrait repartir avec un fichier vide.
    Site : http://chgi.developpez.com

    Pourquoi faire simple quand on peut faire compliqu� ? (Jacques Rouxel)

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 10
    Par d�faut
    Donc faudrai que je remplace a+b par quoi ??
    merci

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 10
    Par d�faut
    c'est bon j'ai trouver, voici mon noueau code qui fonctionn :
    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
     
    //---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    FILE *fp;
    int n = 0;
     
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    fp = fopen("test.bmp", "w+b");
    fclose(fp) ;
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
          TCustomWinSocket *Socket)
    {
       char buf[15000];
       n=Socket->ReceiveBuf(buf,15000);
       fp = fopen("test.bmp","a+b");
       fwrite(buf, 1 , n , fp) ;
       fclose(fp) ;
       rewind(fp) ;
    }
    //---------------------------------------------------------------------------
     
     
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    Form1->Image1->Picture->LoadFromFile("test.bmp");
    }
    //---------------------------------------------------------------------------
     
     
     
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    Application->Terminate();
    }
    //---------------------------------------------------------------------------

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. Probleme de buffer
    Par Flynet dans le forum C++
    R�ponses: 4
    Dernier message: 17/12/2010, 12h52
  2. Probleme avec le vertex buffer
    Par nicoo dans le forum DirectX
    R�ponses: 12
    Dernier message: 19/10/2004, 21h45
  3. Probleme Stencil Buffer
    Par supergrey dans le forum DirectX
    R�ponses: 14
    Dernier message: 20/07/2004, 20h54
  4. [SAX] probleme buffer
    Par ayashi dans le forum Format d'�change (XML, JSON...)
    R�ponses: 8
    Dernier message: 10/06/2004, 16h42

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