Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#3

AW: XML mit Bilder

  Alt 4. Sep 2014, 11:01
Ein kleines Beispiel für Bitmaps, gegf. anzupassen
Delphi-Quellcode:
USES Soap.EncdDecd;

function BitmapToBase64(ABitmap: TBitmap): AnsiString;
var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;
  try
    ABitmap.SaveToStream(MS);
    Result := EncodeBase64(MS.Memory,MS.Size);
  finally
    MS.Free;
  end;
end;

function Base64ToBitmap(const S: AnsiString): TBitmap;
var
  SS: TStringStream;
  B: TBytes;
begin
  B := DecodeBase64(S);
  SS := TStringStream.Create(B);
  try
    Result := TBitmap.Create;
    Result.LoadFromStream(SS);
  finally
    SS.Free;
  end;
end;

procedure TForm5.Button1Click(Sender: TObject);
begin
  Memo1.Text := BitmapToBase64(Image1.Picture.Bitmap);
  Image2.Picture.Bitmap.Assign(Base64ToBitmap(Memo1.Text));
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat