1º ante todo te pido disculpa por no leer tu pos seoane porque es la solucion
.
Lo que no me sale ahora es redibujar la porción de BMP en el cliente
en servidor (que se le entrega al cliente) use el siguiente codigo:
Código Delphi
[-]
unit Umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Jpeg, ZipForge, ScktComp, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient;
type
TFMain = class(TForm)
Button1: TButton;
MainZip: TZipForge; IdTCPClient1: TIdTCPClient;
procedure GetDesktop();
procedure comparar();
procedure FormCreate(Sender: TObject);
procedure Enviar(var streamZip:TStream);
procedure Button1Click(Sender: TObject);
private
public
end;
var
FMain: TFMain;
Recuadro : array [0..1000] of Trect;
BMPEstado:integer=0; Bitmap1,Bitmap2: TBitmap;
StreamZip: TStream;
implementation
{$R *.dfm}
function Min(i,j: Integer): Integer;
begin
if i < j then
Result:= i
else
Result:= j;
end;
function Max(i,j: Integer): Integer;
begin
if i > j then
Result:= i
else
Result:= j;
end;
function Seleccionar(Bitmap_a, Bitmap_b: TBitmap):integer;
var
P1, P2: PByte;
a,b,i, j: Integer;
R: TRect;
intR:integer;
begin
Result:=0;
intR:=0;
b:=0;
R.Right:= 0;
R.Bottom:= 0;
R.Left:= Min(Bitmap_a.Width,Bitmap_b.Width);
R.Top:= Min(Bitmap_a.Height,Bitmap_b.Height);
Bitmap_a.PixelFormat:= pf24bit;
Bitmap_b.PixelFormat:= pf24bit;
for j:= 0 to Min(Bitmap_a.Height,Bitmap_b.Height) - 1 do
begin
a:=0;
P1:= Bitmap_a.ScanLine[j];
P2:= Bitmap_b.ScanLine[j];
for i:= 0 to Min(Bitmap_a.Width,Bitmap_b.Width) - 1 do
begin
if not CompareMem(P1,P2,3) then
begin
R.Right:= Max(i,R.Right);
R.Bottom:= Max(j,R.Bottom);
R.Left:= Min(i,R.Left);
R.Top:= Min(j,R.Top);
a:=1;
b:=1;
end;
inc(P1,3); inc(P2,3);
end;
if (a=0)and(b=1)then
begin
a:=0;b:=0;
Recuadro[intR].Right :=R.Right;
Recuadro[intR].Bottom:=R.Bottom;
Recuadro[intR].Left :=R.Left;
Recuadro[intR].Top :=R.Top;
inc(intR);
R.Right:= 0;
R.Bottom:= 0;
R.Left:= Min(Bitmap_a.Width,Bitmap_b.Width);
R.Top:= Min(Bitmap_a.Height,Bitmap_b.Height);
end;
end;
Result:=intR;
end;
procedure TFMain.comparar();
var
desktop: TCanvas;
Bitmap: TBitmap;
int1,int2:integer;
jpg: TJpegImage;
stream: TStream;
str1:string;
begin
int2:=-1;
Bitmap:= TBitmap.Create;
jpg:=TJPegImage.Create;
StreamZip:=TMemoryStream.Create;
MainZip.OpenArchive(StreamZip,true);
desktop:=TCanvas.Create;
with DeskTop do Handle := GetWindowDC (GetDesktopWindow) ;
try
if BMPEstado=0 then int2:=0;
if BMPEstado=2 then int2:=Seleccionar(Bitmap1,Bitmap2);
if BMPEstado=1 then int2:=Seleccionar(Bitmap2,Bitmap1);
if int2 = -1 then exit;
for int1:=0 to int2 do
begin
Bitmap.Width:= Recuadro[int1].Right - Recuadro[int1].Left;
Bitmap.Height:= Recuadro[int1].Bottom - Recuadro[int1].Top;
if BMPEstado=0 then
begin
Bitmap.Width:= screen.Width;
Bitmap.Height:= screen.Height;
with Bitmap do Canvas.CopyRect(Rect(0,0,Bitmap1.Width, Bitmap1.Height),Bitmap1.Canvas,Rect(0,0,Bitmap1.Width, Bitmap1.Height));
Recuadro[int1].Left:=0;
Recuadro[int1].Top:=0;
Recuadro[int1].Right:=Bitmap.Width;
Recuadro[int1].Bottom:=Bitmap.Height;
end;
if BMPEstado=1 then with Bitmap do Canvas.CopyRect(Rect(0,0,Width,Height),Bitmap1.Canvas,Recuadro[int1]);
if BMPEstado=2 then with Bitmap do Canvas.CopyRect(Rect(0,0,Width,Height),Bitmap2.Canvas,Recuadro[int1]);
str1:=str1+IntToStr(Recuadro[int1].Left)+';';
str1:=str1+IntToStr(Recuadro[int1].Top)+';';
str1:=str1+IntToStr(Recuadro[int1].Right)+';';
str1:=str1+IntToStr(Recuadro[int1].Bottom)+';'+#10;
stream:=TMemoryStream.Create;
jpg.Assign(Bitmap);
jpg.CompressionQuality:=80; jpg.Compress; jpg.SaveToStream(stream);
jpg.SaveToFile(IntToStr(int1)+'.jpg');
stream.Position:=0;
MainZip.AddFromStream(IntToStr(int1)+'.jpg',stream,0,stream.Size);
Stream.Free;
end;
finally
Bitmap.Free;
jpg.Free;
stream:=TMemoryStream.Create;
Stream.WriteBuffer(Pointer(str1)^, Length(str1));
MainZip.AddFromStream('Position.txt',stream,0,stream.Size);
MainZip.CloseArchive;
desktop.Free;
if str1<>'' then
begin
StreamZip.Position:=0;
Enviar(StreamZip);
end;
StreamZip.Free;
end;
end;
procedure TFMain.GetDesktop();
label salto;
var
desktop: TCanvas;
begin
if BMPEstado in[0,2] then
begin
Bitmap1.Width:=screen.Width;
Bitmap1.Height:=screen.Height;
desktop:=TCanvas.Create;
with DeskTop do Handle := GetWindowDC (GetDesktopWindow) ;
with Bitmap1.Canvas do CopyRect (Rect (0, 0, screen.Width, screen.Height),DeskTop,Rect (0, 0, screen.Width, screen.Height));
desktop.Free;
if BMPEstado=0 then
begin
comparar;
BMPEstado:=1;
goto salto;
end;
BMPEstado:=1;
comparar;
goto salto;
end;
if BMPEstado =1 then
begin
Bitmap2.Width:=screen.Width;
Bitmap2.Height:=screen.Height;
desktop:=TCanvas.Create;
with DeskTop do Handle := GetWindowDC (GetDesktopWindow) ;
with Bitmap2.Canvas do CopyRect (Rect (0, 0, screen.Width, screen.Height),DeskTop,Rect (0, 0, screen.Width, screen.Height));
desktop.Free;
BMPEstado:=2;
comparar;
goto salto;
end;
salto:;
end;
procedure TFMain.FormCreate(Sender: TObject);
begin
Bitmap1:= TBitmap.Create;
Bitmap2:= TBitmap.Create;
end;
procedure TFMain.Enviar(var StreamZip:TStream);
begin
IdTCPClient1.Connect;
IdTCPClient1.OpenWriteBuffer;
IdTCPClient1.WriteStream(StreamZip);
IdTCPClient1.CloseWriteBuffer;
IdTCPClient1.Disconnect;
end;
procedure TFMain.Button1Click(Sender: TObject);
begin
GetDesktop; end;
end.
Y en el cliente (osea mi PC
)coloco este codigo:
Código Delphi
[-]
unit Umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, ExtCtrls, ZipForge, IdBaseComponent, IdComponent,
IdTCPServer, StdCtrls, Jpeg;
type
TForm1 = class(TForm)
imgDesktop: TImage;
MainZip: TZipForge; IdTCPServer1: TIdTCPServer;
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
Desktop1:TBitmap;
implementation
{$R *.dfm}
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
AStream,FileStream:TStream;
str1,strPosicion:string;
int1,int2:integer;
jpg: TJpegImage;
Bitmap1: TBitmap;
R:Trect;
begin
with AThread.Connection do
begin
AStream:=TMemoryStream.Create;
ReadStream(AStream, -1, true);
AStream.Position:=0;
MainZip.OpenArchive(AStream,false);
MainZip.ExtractToString('Position.txt',str1);
caption:=str1;
int2:=0;
while length(str1)>0 do
begin
if pos(#10,str1)>0 then
begin
strPosicion:=copy(str1,1,pos(#10,str1)-1);
int1:=pos(';',strPosicion); R.Left:=StrToInt(copy(strPosicion,1,int1-1)); strPosicion:=copy(strPosicion,int1+1,length(strPosicion));
int1:=pos(';',strPosicion); R.Top:=StrToInt(copy(strPosicion,1,int1-1)); strPosicion:=copy(strPosicion,int1+1,length(strPosicion));
int1:=pos(';',strPosicion); R.Right:=StrToInt(copy(strPosicion,1,int1-1)); strPosicion:=copy(strPosicion,int1+1,length(strPosicion));
int1:=pos(';',strPosicion); R.Bottom:=StrToInt(copy(strPosicion,1,int1-1)); strPosicion:=copy(strPosicion,int1+1,length(strPosicion));
str1:=copy(str1,pos(#10,str1)+1,length(str1));
FileStream:=TMemoryStream.Create;
MainZip.ExtractToStream(IntToStr(int2)+'.jpg',FileStream);
FileStream.Position:=0;
jpg:=TJPegImage.Create;
jpg.LoadFromStream(FileStream);
FileStream.Free;
Bitmap1:=TBitmap.Create;
Bitmap1.Assign(jpg);
if Desktop1.Widththen Desktop1.Width:=Bitmap1.Width;
if Desktop1.Heightthen Desktop1.Height:=Bitmap1.Height;
with Desktop1 do Canvas.CopyRect(R,Bitmap1.Canvas,R); imgDesktop.Picture.Assign(Desktop1);
Bitmap1.Free;
jpg.Free;
inc(int2);
end;
end;
MainZip.CloseArchive;
AStream.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Desktop1:=TBitmap.Create;
end;
end.
Como lo indique en el codigo solo me funciona una unica ves el copiar un BMP en una parte de otro BMP
Si a alguien sabe porque por favor me lo puden explicar o indicarme como solucionarlo.
Desde ya muchas gracias a todos por los aportes