Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #8  
Antiguo 10-02-2016
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Poder: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Yo utilizo la API para esos fines:

Código Delphi [-]
const
  CRYPT_STRING_BASE64 = 1;

function CryptBinaryToString(pbBinary: PByte; cbBinary: DWORD; dwFlags: DWORD;
  pszString: PChar; var pcchString: DWORD): BOOL; stdcall;
  external 'Crypt32.dll' name 'CryptBinaryToStringA';

function CryptStringToBinary(pszString: PChar; cchString: DWORD; dwFlags: DWORD;
  pbBinary: PByte; var pcbBinary: DWORD; pdwSkip: PDWORD;
  pdwFlags: PDWORD): BOOL; stdcall;
  external 'Crypt32.dll' name 'CryptStringToBinaryA';

//---------------------------------------------------------------------------
// Codifica un TNMemoryStrean a cadena Encode64
function StreamToStrB64(MStream: TMemoryStream; var Str: String): boolean;
var
  Size: DWORD;
begin
  Result:= CryptBinaryToString(MStream.Memory, MStream.Size, CRYPT_STRING_BASE64, 0 , Size);
  if Result then
  begin
    SetLength(Str, Size);
    Result:= CryptBinaryToString(MStream.Memory, MStream.Size, CRYPT_STRING_BASE64, @Str[1], Size);
  end;
end;

//---------------------------------------------------------------------------
// Decodifica una cadena Encode64 a su binario original en un TMemoryStream
function StrB64ToStream(var Str: String; MStream: TMemoryStream): boolean;
var
  Size: DWORD;
begin
  Result:= CryptStringToBinary(@Str[1], Length(Str), CRYPT_STRING_BASE64, 0, Size, nil, nil);
  if Result then
  begin
    MStream.SetSize(Size);
    Result:= CryptStringToBinary(@Str[1], Length(Str), CRYPT_STRING_BASE64, MStream.Memory, Size, nil, nil);
  end;
end;

Para el tema en cuestión, el uso sería:

Código Delphi [-]
var
  MStream: TMemoryStream;
  S: String;  // Aquí tendremos la cadena BASE64 de la Imagen
begin
  MStream:= TMemoryStream.Create;
  Image1.Picture.Bitmap.SaveToStream(MStream);
  StreamToStrB64(MStream, S);
  MStream.Free;
end;

Por si interesa, aquí mostré un ejemplo de como leer una imagen codificada en BASE64 sin conocer el tipo de la misma usando GDI+.


Saludos,
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Mostrar imagen que viene en Base64 jars Gráficos 7 25-06-2012 09:42:57
Como puedo convertir una imagen a una imagen semitransparente? antonio302050 Gráficos 0 27-03-2010 17:01:48
leer el contenido de un archivo txt ingmichel Varios 6 11-07-2008 15:27:17
Leer Contenido URL adonias Varios 3 14-09-2007 17:12:18
Leer contenido de cd's rruffino Varios 3 09-01-2005 00:56:54


La franja horaria es GMT +2. Ahora son las 16:12:15.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi