Ver Mensaje Individual
  #2  
Antiguo 10-02-2016
Avatar de AgustinOrtu
[AgustinOrtu] AgustinOrtu is offline
Miembro Premium
NULL
 
Registrado: ago 2013
Ubicación: Argentina
Posts: 1.858
Reputación: 15
AgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en bruto
Una alternativa es usando los componentes Indy:

Código Delphi [-]
unit Unit2;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  StdCtrls,
  ExtCtrls,
  IdBaseComponent,
  IdCoder,
  IdCoder3to4,
  IdCoderMIME;

type
  TForm2 = class(TForm)
    IdEncoderMIME1: TIdEncoderMIME;
    imLoad: TImage;
    OpenDialog1: TOpenDialog;
    imBase64: TImage;
    btnLoad: TButton;
    btnToBase64: TButton;
    IdDecoderMIME1: TIdDecoderMIME;
    procedure btnLoadClick(Sender: TObject);
    procedure btnToBase64Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.btnLoadClick(Sender: TObject);
begin
  if not OpenDialog1.Execute then
    Exit;

  imLoad.Picture.LoadFromFile(OpenDialog1.FileName);
end;

procedure TForm2.btnToBase64Click(Sender: TObject);
var
  AImageStream: TMemoryStream;
  AStringStream: TStringStream;
  ABase64, DecodedBase64: string;
begin
  AImageStream := TMemoryStream.Create;
  try
    imLoad.Picture.Graphic.SaveToStream(AImageStream);
    AImageStream.Position := 0;
    ABase64 := IdEncoderMIME1.Encode(AImageStream);
  finally
    AImageStream.Free;
  end;

  DecodedBase64 := IdDecoderMIME1.DecodeString(ABase64);
  AStringStream := TStringStream.Create(DecodedBase64);
  try
    AStringStream.Position := 0;
    imBase64.Picture.Bitmap.LoadFromStream(AStringStream);
  finally
    AStringStream.Free;
  end;
end;

end.
Responder Con Cita