Ver Mensaje Individual
  #3  
Antiguo 03-10-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Yo de bases de datos se lo justo, normalmente no me metería a responder una pregunta sobre este tema, pero con lo de guardar una imagen como si fuera texto, ahí si que te puedo ayudar.

Código Delphi [-]
function BinToStr(Stream: TStream): string;
var
  b: Byte;
  i: integer;
begin
  Result:= '';
  for i:= 1 to  Stream.Size do
  begin
    Stream.Read(b,1);
    Result:= Result + IntToHex(b,2);
  end;
end;

procedure StrToBin(Stream: TStream; var Str: string);
var
  i: integer;
  b: integer;
begin
  i:= 1;
  while i < Length(Str) do
  begin
    if TryStrToInt('$' + Copy(Str,i,2),b) then
    begin
      Stream.Write(b,1);
    end else
      Exit;
    inc(i,2);
  end;
end;


// Pasar un fichero a un string
var
  Str: string;
  Stream: TFileStream;
begin
  Stream:= TFileStream.Create('d:\1.jpg',fmOpenRead);
  with Stream do
  try
    Str:= BinToStr(Stream);
    // El archivo esta en la cadena de texto, ahora
    // puedes hacer lo que quieras con el texto
  finally
    Free;
  end;
end;

// Pasar un string a un fichero
var
  Str: string;
  Stream: TFileStream;
begin
  // Obten el texto y colocalo en Str
  Stream:= TFileStream.Create('d:\2.jpg',fmCreate);
  with Stream do
  try
    StrToBin(Stream,Str);
  finally
    Free;
  end;
end;

El algoritmo anterior no es una maravilla, de hecho duplica el tamaño necesario para guardar el archivo. Es un comienzo, aunque yo te recomiendo que busques información sobre la codificación base64 mucho mas eficiente.
Responder Con Cita