procedure TForm1.CarregaImagem2(url: String; Picture: TPicture);
var
iHttpImg : TIdHTTP;
imgStream : TMemoryStream;
pngImage : TPortableNetworkGraphic;
begin
ShowMessage(url);
pngImage := TPortableNetworkGraphic.Create;
try
imgStream := TMemoryStream.Create;
try
iHttpImg := TIdHTTP.Create;
try
iHttpImg.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0; Waterfox) Gecko/20100101 Firefox/56.2.3';
iHttpImg.Request.Accept := 'image/png';
iHttpImg.Get(url, imgStream);
if not IsHeaderMediaType(iHttpImg.Response.ContentType, 'image/png') then
raise Exception.Create('Incorrect image type');
finally
iHttpImg.Free;
end;
imgStream.Position := 0;
pngImage.LoadFromStream(imgStream);
finally
imgStream.Free;
end;
Picture.Assign(pngImage);
finally
pngImage.Free;
end;
end;
procedure TForm1.CarregaImagem2(url: String; Picture: TPicture);
var
iHttpImg : TIdHTTP;
imgStream : TMemoryStream;
fileExt: string;
begin
ShowMessage(url);
imgStream := TMemoryStream.Create;
try
iHttpImg := TIdHTTP.Create;
try
iHttpImg.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0; Waterfox) Gecko/20100101 Firefox/56.2.3';
iHttpImg.Request.Accept := 'image/*';
iHttpImg.Get(url, imgStream);
if not IsHeaderMediaType(iHttpImg.Response.ContentType, 'image') then
raise Exception.Create('Incorrect image type');
fileExt := ExtractFileExt(ExtractHeaderSubItem(iHttpImg.Response.ContentDisposition, 'filename', QuoteHTTP));
if fileExt = '' then
fileExt := ExtractFileExt(ExtractHeaderSubItem(iHttpImg.Response.ContentType, 'name', QuoteHTTP));
if fileExt = '' then
fileExt := GetMIMEDefaultFileExt(ExtractHeaderItem(iHttpImg.Response.ContentType));
if fileExt = '' then
raise Exception.Create('Unknown file extension');
finally
iHttpImg.Free;
end;
imgStream.Position := 0;
Picture.LoadFromStreamWithFileExt(imgStream, fileExt);
finally
imgStream.Free;
end;
end;
iHttpImg.Get('https://cdn-cosmos.bluesoft.com.br/products/7891910000197',imgStream);
productID := '7891910000197';
url := 'https://cdn-cosmos.bluesoft.com.br/products/'+productID;
iHttpImg.Get(url,imgStream);