There seems to be no direct way to save image element to a file, so I would get it from cache. To copy a file from the IE cache by a given resource URL you may use a function like follows. The URL
parameter is the src
attribute value of the HTML tag and FileName
is the target file name:
uses
WinInet;
procedure SaveInetResourceToFile(const URL, FileName: string);
var
BufferSize: DWORD;
CacheEntry: PInternetCacheEntryInfo;
begin
if not RetrieveUrlCacheEntryFile(PChar(URL), TInternetCacheEntryInfo(nil^),
BufferSize, 0) then
begin
if GetLastError = ERROR_INSUFFICIENT_BUFFER then
begin
GetMem(CacheEntry, BufferSize);
try
if RetrieveUrlCacheEntryFile(PChar(URL), CacheEntry^, BufferSize, 0) then
try
Win32Check(CopyFile(CacheEntry.lpszLocalFileName, PChar(FileName),
False));
finally
Win32Check(UnlockUrlCacheEntryFile(PChar(URL), 0));
end
else
RaiseLastOSError;
finally
FreeMem(CacheEntry);
end;
end
else
RaiseLastOSError;
end;
end;