Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: How to convert a bitmap to Base64 string with Indy?

www.cryer.info
Managed Newsgroup Archive

Re: How to convert a bitmap to Base64 string with Indy?

Subject:Re: How to convert a bitmap to Base64 string with Indy?
Posted by:"Ma Xiaoming" (maxiaoming100..@hotmail.com)
Date:Fri, 14 Dec 2007 13:59:53

Hi,

   I have tried to convert a bitmap to Base64 string as following:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

procedure TForm1.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
  mStream: TMemoryStream;
  bArray: array of Integer;
  i: Integer;
  s: string;
  s64: string;
begin
  bmp := TBitmap.Create;
  mStream := TMemoryStream.Create;
  try
    bmp.Width := 100;
    bmp.Height := 100;
    bmp.PixelFormat := pf24bit;
    bmp.SaveToStream(mStream);
    mStream.Position := 0;

    SetLength( bArray, Integer(mStream.Size) );
    for i := 0 to High(bArray) do
    begin
      mStream.Read(bArray[i], 1);
    end;

    for i := 0 to High(bArray) do
    begin
      s := s + IntToStr(bArray[i]);
    end;

    s64 := IDBase64Encoder1.CodeString(s);

    for i := 1 to 1000 do
    begin
      ListBox1.Items.Add(s64[i]);
    end;
  finally
    bmp.Free;
    mStream.Free;
  end;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   It seems work, am I right?

   Best regards.

   Xiaoming

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive