मैं एक TidHttp घटक का उपयोग कर वेब से बड़ी संख्या में छवियों को पुनर्प्राप्त करने का प्रयास कर रहा हूं।यूआरएल से जेपीईजी छवियों को डाउनलोड करने के लिए TidHttp का उपयोग करना (केवल वे मौजूद हैं)?
समस्या छवियों कि याद कर रहे हैं की एक संख्या है कि हो (उदाहरण: 7403, 7412, आदि)
मैं कैसे केवल उन है कि मौजूद हैं और उन फाइल करने के लिए बचाने के लिए परीक्षण करते हैं?
procedure TForm.Button1Click(Sender: TObject);
var
MS : TMemoryStream;
JPEGImage: TJPEGImage;
Url, numString: String;
I, Code: Integer;
begin
for I := 7400 to 7500 do
begin
{
Url :='http://www.mywebpage.com/images/DSC' + numString+ '.jpg';
try
idhttp1.Head(URL);
code := idhttp1.ResponseCode;
except on E: EIdHTTPProtocolException do
code := idhttp1.ResponseCode;
end;//try except
if code = 200 then
begin
MS := TMemoryStream.Create;
JPEGImage := TJPEGImage.Create;
try
try
idhttp1.Get(Url, MS); //Send the request and get the image
code := idhttp1.ResponseCode;
MS.Seek(0,soFromBeginning);
JPEGImage.LoadFromStream(MS);//load the image in a Stream
Image1.Picture.Assign(JPEGImage);//Load the image in a Timage component
Image1.Picture.SaveToFile('C:\Museum_Data\DSC' + numString + '.jpg');
Application.ProcessMessages;
except
on E: EIdHTTPProtocolException do
code := idhttp1.ResponseCode; // or: code := E.ErrorCode;
end; //try except
finally
MS.free;
JPEGImage.Free;
end; //try finally
end; //if
end;
end;
जहां तक मैं आपको देख सकता हूं कि आप पहले से ही ऐसा करते हैं, अगर प्रतिक्रिया 200 तस्वीर के लिए जाती है, लेकिन मुझे नहीं लगता कि numString चर परिभाषित किया गया है –