I'm trying to crawl a large number of images from my old website because it's soon going to be shut down. All of the images are in JPEG format, all of them are actually downloaded from the website, but some of them are shown in a green-pink accent on my local (Windows) computer.
I found out none of the corrupted pictures have color-space metadata and embedded color profile, but I'm not sure this is the problem, since I'm not familiar with image processing. I couldn't find any setting in C# to set the color profile to RGB or something similar. This is my code:
private static Image GetImageFromUrl(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
try
{
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (Stream stream = httpWebReponse.GetResponseStream())
{
return Image.FromStream(stream);
}
}
}
catch (WebException e)
{
return null;
}
}
private static void SaveImage(string folderName, string fileName, Image img)
{
if (img == null || folderName == null || folderName.Length == 0)
{
return;
}
string path = "D:\\Files\\" + folderName;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
using (img)
{
img.Save("D:\\Files\\" + folderName + "\\" + fileName, ImageFormat.Jpeg);
}
}
SaveImage(folderName, fileName, GetImageFromUrl(resultUrl));
This is how the pictures look like in the browser (left) and when downloading with this program (right):
Thank you for your help.