以二进制方式读取图片保存到string

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  StringStream : TStringStream;
  FSize : integer;
  FileData : string;
  i : integer;
  DataStr : string;
  msStream: TMemoryStream;
begin

  msStream:= TMemoryStream.Create;
  self.img1.Picture.Graphic.SaveToStream(msStream);
  msStream.Position:=0;
  StringStream := TStringStream.Create(EmptyStr);
  fsize:=msStream.Size;
  StringStream.CopyFrom(msStream, FSize);
  FileData := StringStream.DataString;
  self.ProgressBar1.Max:=StringStream.Size;
  DataStr := EmptyStr;
  for i := 1 to Length(FileData) do
    begin
      DataStr := DataStr + InttoHex(Ord(FileData[i]), 2); // 十六进制显示
  // DataStr:=DataStr+er(Ord(FileData[i]),7)// 二进制显示
      self.ProgressBar1.Position:=i;
     Application.ProcessMessages ;
    end;
     //Memo1.Text:=DataStr;
   self.RichEdit1.Text:=DataStr;
  Application.ProcessMessages ;

end;

你可能感兴趣的:(String)