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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  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 dé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