본문 바로가기

Academy I/Tech Academy

[Delphi]Save to Internet Image

var
  oXMLHTTP: OleVariant;
  MemoryStream: TMemoryStream;
  Stream: IStream;
  OleStream: TOleStream;
begin
  oXMLHTTP := CreateOleObject('MSXML2.XMLHTTP.3.0');
  oXMLHTTP.open('GET', 'https://www.google.com/images/srpr/logo11w.png', False);
  oXMLHTTP.send(EmptyParam);
  Stream := IUnknown(oXMLHTTP.ResponseStream) as IStream;
  OleStream := TOleStream.Create(Stream);
  try
    OleStream.Position := 0;
    MemoryStream := TMemoryStream.Create;
    try
      MemoryStream.CopyFrom(OleStream, OleStream.Size);
      MemoryStream.SaveToFile('logo11w.png');
    finally
      MemoryStream.Free;
    end;
  finally
    OleStream.Free;
  end;