Advertisement
maskofa

Bitmap <> Base64

Jun 17th, 2019
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.08 KB | None | 0 0
  1. function CodBase64(const ABitmap: TBitmap): string;
  2. var
  3.   LInputStream: TBytesStream;
  4.   LOutputStream: TStringStream;
  5. begin
  6.   Result := '';
  7.   if ABitmap.IsEmpty then
  8.     Exit;
  9.  
  10.   LInputStream := TBytesStream.Create;
  11.   try
  12.     ABitmap.SaveToStream(LInputStream);
  13.     LInputStream.Position := 0;
  14.     LOutputStream := TStringStream.Create('');
  15.     try
  16.       TNetEncoding.Base64.Encode(LInputStream, LOutputStream);
  17.       Result := LOutputStream.DataString;
  18.     finally
  19.       LOutputStream.Free;
  20.     end;
  21.   finally
  22.     LInputStream.Free;
  23.   end;
  24. end;
  25.  
  26. procedure DecodBase64(const ASource: string; const ABitmap: TBitmap);
  27. var
  28.   LInputStream: TStringStream;
  29.   LOutputStream: TBytesStream;
  30. begin
  31.   LInputStream := TStringStream.Create(ASource);
  32.   try
  33.     LInputStream.Position := 0;
  34.     LOutputStream := TBytesStream.Create;
  35.     try
  36.       TNetEncoding.Base64.Decode(LInputStream, LOutputStream);
  37.       LOutputStream.Position := 0;
  38.       ABitmap.LoadFromStream(LOutputStream);
  39.     finally
  40.       LOutputStream.Free;
  41.     end;
  42.   finally
  43.     LInputStream.Free;
  44.   end;
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement