/// <summary> /// Get the dimesions of an Image object. This is SLOW. /// </summary> /// <param name="imageURL"></param> /// <returns>An image with dimensions object</returns> private ImageWithDimensions GetDimensionsFromImage(Image image) { ImageWithDimensions imageWD = new ImageWithDimensions(); var stream = new System.IO.MemoryStream(); image.Save(stream, ImageFormat.Jpeg); using (Image jpg = Image.FromStream(stream: stream, useEmbeddedColorManagement: false, validateImageData: false)) { imageWD.Width = Convert.ToInt32(jpg.PhysicalDimension.Width); imageWD.Height = Convert.ToInt32(jpg.PhysicalDimension.Height); } imageWD.Image = image; return imageWD; }
public List<ImageWithDimensions> FindImages(string HTML) { // Get img tags from HTML List<string> imgTags = GetImgTagsFromHTML(HTML); // Get img src from img tags List<string> imgURLS = GetImgURLSFromTag(imgTags); // Set up ImageWD Object list List<ImageWithDimensions> ImageWDs = new List<ImageWithDimensions>(); foreach (var imgURL in imgURLS) { ImageWithDimensions image = new ImageWithDimensions(); image = GetDimensionsFromImage(DownloadImageFromURL(imgURL)); ImageWDs.Add(image); } return ImageWDs; }