Bonjour tout le monde, j'ai réalisé il y'a quelques temps une petite application en Delphi dont la fonction était d'envoyer une capture d'écran par streaming via les composants tcp Indy à une autre application serveur. La déscription et les sources sont ici :
http://www.delphifr.com/code.aspx?id=26586
Je sais j'ai parlé de Delphi mais si je post ici c'est parce que j'ai réalisé la même application avec Borland c++ builder 6 pour ceux que ca interesse.... Voilà.
La déscription de cette source est la même que pour celle en Delphi donc vous pouvez vous y reporter pour les détails.
Source / Exemple :
// Partie client : code de unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <jpeg.hpp> //inclusion de jpeg.hpp
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
//Définition de la procedure qui capture l'écran et converti en jpg
//puis envois le tout par tcp
void sendstr()
{
TMemoryStream *stream = new TMemoryStream();
TJPEGImage *jpg = new TJPEGImage();
Graphics :: TBitmap *bmp = new Graphics :: TBitmap();
TRect *rect = new TRect();
TPicture *img = new TPicture();
img->Bitmap->Height = Screen->Height;
img->Bitmap->Width = Screen->Width;
int scrw = Screen->Width, scrh = Screen->Height;
HWND hwnd = GetDesktopWindow();
HDC hDC = GetDC(hwnd);
BitBlt(img->Bitmap->Canvas->Handle,0,0,scrw,scrh,hDC,0,0,SRCCOPY);
try
{
jpg->Assign(img->Bitmap);
jpg->CompressionQuality = 15;
bmp->Width = jpg->Width -50;
bmp->Height = jpg->Height -50;
rect->Left = 0;
rect->Top = 0;
rect->Right = bmp->Width-1;
rect->Bottom = bmp->Height-1;
bmp->Canvas->StretchDraw(*rect,jpg);
jpg->Assign(bmp);
jpg->SaveToStream(stream);
jpg->Free();
bmp->Free();
img->Free();
}
catch (...)
{
}
try
{
Form1->tcp->OpenWriteBuffer();
Form1->tcp->WriteStream(stream);
Form1->tcp->CloseWriteBuffer();
stream->Free();
Form1->tcp->Disconnect();
}
catch(...)
{
}
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
// Edit2->Text.ToIntDef(1000) converti la chaine contenue dans Edit2 en Entiers
//Si la conversion n'est pas possible l'interval prend la valeure 1000
Timer1->Interval = Edit2->Text.ToIntDef(1000) ;
tcp->Host = Edit1->Text;
Timer1->Enabled = true;
}
catch(...)
{
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
try
{
Timer1->Enabled = false;
}
catch(...)
{
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
try
{
tcp->Connect();
sendstr();
}
catch(...)
{
Timer1->Enabled = false;
ShowMessage("Connexion Impossible");
}
}
//Partie serveur : code de unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <jpeg.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::tcpExecute(TIdPeerThread *AThread)
{
TMemoryStream *stream = new TMemoryStream();
TJPEGImage *jpg = new TJPEGImage();
AThread->Connection->ReadStream(stream, -1, true); //réception du stream
stream->Position =0;
jpg->LoadFromStream(stream);
Image1->Picture->Graphic = jpg; //affichage dans TImage
stream->Free();
jpg->Free();
}
Conclusion :
Si vous lisez le post sur la source Delphi rapidement, vous n'aurez aucun mal à faire le rapprochement avec cette source ci.... De toute facon il y'a un zip ;)
Bonne journée!
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.