In this code Base64FromBitmap() converts an image to a string, then, the result will appear in a RichEdit. Sometimes, this process takes a few seconds (based on the size of an image). I want to add a Progressbar that shows the progress until complete the process. There is no For loop in the Base64FromBitmap() function.
function Base64FromBitmap(Bitmap: TBitmap): string;
var
Input: TBytesStream;
Output: TStringStream;
Encoding: TBase64Encoding;
begin
Input := TBytesStream.Create;
try
Bitmap.SaveToStream(Input);
Input.Position := 0;
Output := TStringStream.Create('', TEncoding.ASCII);
try
Encoding := TBase64Encoding.Create(0);
try
Encoding.Encode(Input, Output);
Result := Output.DataString;
finally
Encoding.Free;
end;
finally
Output.Free;
end;
finally
Input.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
begin
s := Base64FromBitmap(Image1.Picture.Bitmap);
RichEdit.Text := s;
end;