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
| procedure TFrmShowJPEG.BtnSendClick(Sender: TObject);
var
Index: Integer;
DummyJPEg: TJPEGImage;
DummyBitmap: TBitmap;
DummyStream: TMemoryStream;
begin
DummyJPEg := TJPEGImage.Create();
try
DummyBitmap := TBitmap.Create();
try
DummyStream := TMemoryStream.Create();
try
DummyBitmap.Assign(ImageWithDate.Picture.Bitmap);
DummyBitmap.Canvas.TextOut(0, 0, 'Copy');
// DummyBitmap.SaveToStream(DummyStream);
DummyJPEg.Assign(DummyBitmap);
DummyJPEg.SaveToStream(DummyStream);
if DummyStream.Size > 0 then
begin
for Index := 0 to ServerSocketJPEG.Socket.ActiveConnections - 1 do
begin
if ServerSocketJPEG.Socket.Connections[Index].Connected then
ServerSocketJPEG.Socket.Connections[Index].SendBuf(DummyStream.Memory^, DummyStream.Size);
begin
lblRead.Caption := 'Envoyé ...';
end;
Application.ProcessMessages();
end;
end else
begin
lblRead.Caption := 'Stream Vide ...';
end;
finally
DummyStream.Free(); // Voir l'aide de Delphi pour le TCustomWinSocket.SendStream
end;
finally
DummyBitmap.Free();
end;
finally
DummyJPEg.Free();
end;
end;
procedure TFrmShowJPEG.ClientSocketJPEGRead(Sender: TObject;
Socket: TCustomWinSocket);
var
DummyStream: TMemoryStream;
DummyJPEg: TJPEGImage;
Count, TotalCount: Integer;
Buffer: Pointer;
begin
ClientSocketJPEG.OnRead := nil;
try
lblRead.Caption := 'Réception ...'; lblRead.Refresh();
try
DummyStream := TMemoryStream.Create();
try
Count := 0;
TotalCount := 0;
repeat
lblRead.Caption := 'Réception ... ' + IntToStr(Socket.ReceiveLength) + ' / ' + IntToStr(TotalCount) + ' '; lblRead.Refresh();
DummyStream.SetSize(TotalCount+Socket.ReceiveLength);
Count := Socket.ReceiveBuf(Pointer(Integer(DummyStream.Memory)+TotalCount)^, Socket.ReceiveLength);
Inc(TotalCount, Count);
MemoLog.Lines.Add(lblRead.Caption);
Application.ProcessMessages();
until Count <= 0;
DummyJPEg := TJPEGImage.Create();
try
DummyJPEg.LoadFromStream(DummyStream);
ImageRead.Picture.Bitmap.Assign(DummyJPEg);
finally
DummyJPEg.Free();
end;
finally
DummyStream.Free();
end;
lblRead.Caption := 'Terminé !';
except
lblRead.Caption := 'Except : ' + Exception(ExceptObject).Message;
end;
finally
ClientSocketJPEG.OnRead := ClientSocketJPEGRead;
end;
end; |