मैं साइट से छवियों को डाउनलोड करने का प्रयास कर रहा हूं। जिस कोड का मैं उपयोग कर रहा हूं वह ठीक काम कर रहा है जबकि छवि उपलब्ध है। अगर यह छवि उपलब्ध नहीं है तो यह एक समस्या पैदा कर रही है। छवि की उपलब्धता को कैसे सत्यापित करें?साइट से छवि डाउनलोड करें .NET/C#
कोड:
विधि 1:
WebRequest requestPic = WebRequest.Create(imageUrl);
WebResponse responsePic = requestPic.GetResponse();
Image webImage = Image.FromStream(responsePic.GetResponseStream()); // Error
webImage.Save("D:\\Images\\Book\\" + fileName + ".jpg");
विधि 2:
WebClient client = new WebClient();
Stream stream = client.OpenRead(imageUrl);
bitmap = new Bitmap(stream); // Error : Parameter is not valid.
stream.Flush();
stream.Close();
client.dispose();
if (bitmap != null)
{
bitmap.Save("D:\\Images\\" + fileName + ".jpg");
}
संपादित करें:
स्ट्रीम है निम्नलिखित बयानों:
+०१२३५१६४१० Length '((System.Net.ConnectStream)(str)).Length' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException}
Position '((System.Net.ConnectStream)(str)).Position' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException}
ReadTimeout 300000 int
WriteTimeout 300000 int
लपेटें अपमानजनक बयान का उपयोग करने के लिए 'कोशिश - catch', और अपवाद विवरण उपलब्ध कराएं। – gimel
लाइन बिटमैप = नया बिटमैप (स्ट्रीम); त्रुटि दिखाता है: पैरामीटर वैध नहीं है। – Geeth