Recent

Author Topic: An error occurred while loading the network image using idhttp  (Read 231 times)

yzsdn

  • New member
  • *
  • Posts: 5
hi.

I had a format error loading a network image using idhttp

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. var
  4.     imagestream:TMemoryStream;
  5.     jpg:TJpegImage;
  6. begin
  7.     imagestream := TMemoryStream.Create();
  8.     jpg:=TJpegImage.Create;
  9.     idhttp1.Get('https://p1.music.126.net/8W5e0ZO7lFS-HtXEEi_HzQ==/109951164582961512.jpg',imagestream);
  10.     imagestream.Position:=0;
  11.     jpg.LoadFromStream(imagestream);
  12.     image1.Picture.Assign(jpg);
  13. end;
  14.  
  15.  

If you change the URL to another, it will display normally
I've browsed the relevant solutions, but I still can't solve it
« Last Edit: August 10, 2020, 03:30:20 pm by yzsdn »

paweld

  • Full Member
  • ***
  • Posts: 241
Re: An error occurred while loading the network image using idhttp
« Reply #1 on: August 10, 2020, 08:02:25 pm »
because it's not jpeg file.
Code: Pascal  [Select][+][-]
  1. var
  2.   imagestream: TMemoryStream;
  3. begin
  4.   imagestream := TMemoryStream.Create();
  5.   idhttp1.Get('https://p1.music.126.net/8W5e0ZO7lFS-HtXEEi_HzQ==/109951164582961512.jpg', imagestream);
  6.   imagestream.Position := 0;
  7.   image1.Picture.LoadFromStream(imagestream);
  8.   imagestream.Free;
  9. end;      

or if you absolutely want a jpg file:
Code: Pascal  [Select][+][-]
  1. var
  2.   imagestream: TMemoryStream;
  3.   pic: TPicture;
  4. begin
  5.   imagestream := TMemoryStream.Create();
  6.   pic := TPicture.Create;
  7.   idhttp1.Get('https://p1.music.126.net/8W5e0ZO7lFS-HtXEEi_HzQ==/109951164582961512.jpg', imagestream);
  8.   imagestream.Position := 0;
  9.   pic.LoadFromStream(imagestream);
  10.   image1.Picture.Jpeg := pic.Jpeg;
  11.   pic.Jpeg.SaveToFile('picture.jpg');
  12.   imagestream.Free;
  13.   pic.Free;
  14. end;    
« Last Edit: August 10, 2020, 08:10:42 pm by paweld »
Best regards
paweld

yzsdn

  • New member
  • *
  • Posts: 5
Re: An error occurred while loading the network image using idhttp
« Reply #2 on: August 11, 2020, 05:00:51 pm »
because it's not jpeg file.
Code: Pascal  [Select][+][-]
  1. var
  2.   imagestream: TMemoryStream;
  3. begin
  4.   imagestream := TMemoryStream.Create();
  5.   idhttp1.Get('https://p1.music.126.net/8W5e0ZO7lFS-HtXEEi_HzQ==/109951164582961512.jpg', imagestream);
  6.   imagestream.Position := 0;
  7.   image1.Picture.LoadFromStream(imagestream);
  8.   imagestream.Free;
  9. end;      

or if you absolutely want a jpg file:
Code: Pascal  [Select][+][-]
  1. var
  2.   imagestream: TMemoryStream;
  3.   pic: TPicture;
  4. begin
  5.   imagestream := TMemoryStream.Create();
  6.   pic := TPicture.Create;
  7.   idhttp1.Get('https://p1.music.126.net/8W5e0ZO7lFS-HtXEEi_HzQ==/109951164582961512.jpg', imagestream);
  8.   imagestream.Position := 0;
  9.   pic.LoadFromStream(imagestream);
  10.   image1.Picture.Jpeg := pic.Jpeg;
  11.   pic.Jpeg.SaveToFile('picture.jpg');
  12.   imagestream.Free;
  13.   pic.Free;
  14. end;    
Thank you very much. You solved my problem

 

TinyPortal © 2005-2018