Convert BitMap to string without line breaks?

前端 未结 2 1000
别跟我提以往
别跟我提以往 2020-12-11 10:50

Somewhere I found this code to convert a BitMap to a string:

function Base64FromBitmap(Bitmap: TBitmap): string;
var
  Input: TBytesStream;
  Output: TString         


        
2条回答
  •  执念已碎
    2020-12-11 11:39

    Soap.EncdDecd.EncodeStream() is hard-coded to output a line break every 75 characters. The only way to change that is to make a copy of Soap.EncdDecd.pas, edit it, and then add the copy to your project (and this approach does not work if your project has Runtime Packages enabled).

    You can use Indy's TIdEncoderMIME class as an alternative. It does not output line breaks:

    uses
      ..., IdCoderMIME;
    
    function Base64FromBitmap(Bitmap: TBitmap): string;
    var
      Input: TMemoryStream;
    begin
      Input := TMemoryStream.Create;
      try
        Bitmap.SaveToStream(Input);
        Input.Position := 0;
        Result := TIdEncoderMIME.EncodeStream(Input);
      finally
        Input.Free;
      end;
    end;
    

提交回复
热议问题