Created
March 14, 2022 18:08
-
-
Save reinaldoacdc/5d8bffa7eb0d03c105cbac44e99c02e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit BitmapHelper; | |
interface | |
uses FMX.Graphics; | |
type | |
TBitmapHelper = class helper for TBitmap | |
function ToBase64 :String; | |
end; | |
implementation | |
uses System.Classes, System.SysUtils, System.NetEncoding; | |
{ TBitmapHelper } | |
function TBitmapHelper.ToBase64: String; | |
var | |
Input: TBytesStream; | |
Output: TStringStream; | |
Encoding: TBase64Encoding; | |
begin | |
Input := TBytesStream.Create; | |
try | |
Self.SaveToStream(Input); | |
Input.Position := 0; | |
Output := TStringStream.Create('', TEncoding.ASCII); | |
try | |
Encoding := TBase64Encoding.Create(0); | |
Encoding.Encode(Input, Output); | |
Result := Output.DataString; | |
finally | |
Encoding.Free; | |
Output.Free; | |
end; | |
finally | |
Input.Free; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment