尝试将远程PNG文件分配给TImage。我试过跟踪,它说"无效的流格式"。我不知道如何将PNG图像下载到Firemonkey风格的应用程序(XE8):
procedure TfrmMain.Button1Click(Sender: TObject);
var qrString: String;
MS : TMemoryStream;
Png: TImageMultiResBitmap;
begin
MS := TMemoryStream.Create;
Png := TImageMultiResBitmap.Create(Png);
try
IdHTTP1.get('https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=chujisko',MS);
Ms.Seek(0,soFromBeginning);
Png.LoadFromStream(MS);
img1.MultiResBitmap.Assign(Png);
finally
FreeAndNil(Png);
FreeAndNil(MS);
end;
答案 0 :(得分:0)
所以小伙子们,这似乎是正确可靠的解决方案:
procedure TfrmMain.Button1Click(Sender: TObject);
var qrString: String;
qrDims: integer;
MS : TMemoryStream;
begin
if Edit1.Text <> '' then begin
qrDims := Screen.Width - 100;
qrString := 'http://chart.googleapis.com/chart?chs=' + IntToStr(qrDims) + 'x' + IntToStr(qrDims) + '&cht=qr&chl=' + Edit1.Text;
MS := TMemoryStream.Create;
try
IdHTTP1.get(qrString, MS);
Ms.Seek(0,soFromBeginning);
img1.Bitmap.LoadFromStream(MS);
img1.Bitmap.SaveToFile();
finally
FreeAndNil(MS);
end;
end else begin
ShowMessage('Please, input a text.');
end;
end;