Entendido
escafandrada
Pero al final tienes que crear un stream para pasarle la imagen, es decir solo nos ahorramos el componente TPng pero se "complica" un poco usando las GDI (que tengo que estudiarlas a fondo, gracias por el ejemplo). La funcion "PintaPantalla" con componentes tarda entre 64 y 78 ms en realizar la operacion en casi cualquier PC.
Es las pruebas que he realizado (por cierto que he "cargado" los componentes Indy de la parte del servidor y los e reemplazado por socket, ya sabes bind, linten, accept y thread, luego los sustituyo en el cliente) la eficiencia es similar. Donde mas me preocupa la eficiencia es la copia de zonas de memoria.
Ahora tengo un "RxBuffer: array[0..65535] of ansichar;" en el servidor que lo recoje de "RxLen := recv(nSocket, RxBuffer, 65536, 0);" y veras que tengo un bucle for para copiar el contenido, ahi si creo que estoy fallando en rendimiento. No veo la funcion que permite esa copia de memoria tipo strcopy etc ¿sabes tu cual es?
Bueno en realizad tengo una zona donde recibo del socket que "RxBuffer" y lo copio con "for" al onRecibido y este "ServidorRecibido" incrementa el buffer para generar la imagen. Tambien seria genial saber cual es la funcion que copia, o mejor dicho, incrementa un buffer con el contenido de otro.
Gracias por seguir el tema (curiosa las funciones Lock/UnLock del bitmap, jejeje)
Código Delphi
[-]
var
SCRBuffer: array of ansichar;
procedure TFormPantalla.ServidorRecibido(Sender: TObject);
var
i, rec, p: integer;
begin
p := SCRrec; rec := ServidorSCR.RxLen;
Inc(SCRRec, rec);
SetLength(SCRbuffer, SCRRec);
for i := 0 to rec - 1 do
SCRBuffer[p + i] := ServidorSCR.RxBuffer[i];
if (GetTickCount() - tOutLoad) > 5000 then
begin
Application.MessageBox('TimeOut > 5000 ms', 'Atención', MB_ICONWARNING + MB_OK);
Imagen.Picture := nil;
Imagen.Refresh;
SCRSize := 0;
SCRRec := 0;
SetLength(SCRBuffer, 0);
GaugeLoad.Progress := 0;
GaugeLoad.Refresh;
tOutLoad := GetTickCount();
Exit;
end;
GaugeLoad.Progress := Length(SCRBuffer);
GaugeLoad.Refresh;
tOutLoad := GetTickCount();
if SCRrec = SCRSize then
begin
PintaPantalla();
SCRSize := 0;
SCRRec := 0;
SetLength(SCRBuffer, 0);
tFinLoad := GetTickCount();
STtimeLoad.Caption := IntToStr(tFinLoad - tIniLoad) + ' ms.';
Pidepantalla();
end;
end;
procedure TFormPantalla.ProcesaPantalla(recibido: string);
begin
SCRSize := StrToIntDef(Copy(recibido, 6, Length(recibido) - 6), 0);
GaugeLoad.MaxValue := SCRSize;
GaugeLoad.Refresh;
end;
procedure TFormPantalla.PintaPantalla();
var
LStream: TMemoryStream;
LPngImage: TPngImage;
begin
LStream := TMemoryStream.Create;
LPngImage := TPngImage.Create;
try
LStream.Write(SCRBuffer[0], SCRSize);
LStream.Position := 0;
LPngImage.Canvas.Lock;
LPngImage.LoadFromStream(LStream);
LPngImage.Canvas.Unlock;
Imagen.Picture.Assign(LPngImage);
Imagen.Refresh;
finally
LStream.Free;
LPngImage.Free;
end;
end;
procedure TFormPantalla.PidePantalla;
var
msg: ansistring;
begin
tIniLoad := GetTickCount();
tOutLoad := tIniLoad;
msg := '[OKSCR]' + #13 + #10;
ClienteCMD.Envia(AnsiString(msg));
end;