Reference the built-in unit of Delphi first
Uses encddecd;
Then you can use the following two functions:
By poplar http://yjmyzz.cnblogs.com under the bodhi tree/
/// Convert Bitmap bitmap to a base64 string
Function Bitmaptostring (IMG: tbitmap ): String ;
VaR
MS: tmemorystream;
SS: tstringstream;
S: String ;
Begin
MS: = Tmemorystream. Create;
IMG. savetostream (MS );
SS: = Tstringstream. Create ( '' );
Ms. Position: = 0 ;
Encodestream (MS, SS ); // Encode the memory stream as a base64 bytes stream
S: = SS. datastring;
Ms. Free;
SS. Free;
Result: = S;
End ;
/// Converts a base64 string to A Bitmap bitmap.
Function Stringtobitmap (imgstr: String ): Tbitmap;
VaR SS: tstringstream;
MS: tmemorystream;
Bitmap: tbitmap;
Begin
SS: = Tstringstream. Create (imgstr );
MS: = Tmemorystream. Create;
Decodestream (SS, MS ); // Restore base64 streams to memory streams
Ms. Position: = 0 ;
Bitmap: = Tbitmap. Create;
Bitmap. loadfromstream (MS );
SS. Free;
Ms. Free;
Result: = Bitmap;
End ;