How to create stream image in Angle Sharp

366 Views Asked by At

I need to create a stream image from IHtmlImageElement.

In HtmlUnit, I'm using this:

HtmlImage image;
ImageReader reader = image.getImageReader();

So, how could I make this in AngleSharp?

1

There are 1 best solutions below

0
On BEST ANSWER

AngleSharp has only the knowledge that there is something like an img element with, e.g., a src attribute - it does not have the image stream (out of the box).

Getting an image stream can also be done fully independent of AngleSharp (see https://github.com/AngleSharp/AngleSharp/blob/master/doc/Questions.md#how-to-download-a-picture for details).

Now if you want to get the src of an image just do something like

var src = document.QuerySelector<IHtmlImageElement>("img#my-awesome-img-element").Source;

where document is the document (IHtmlDocument) instance and #my-awesome-img-element is the ID of the image element. You can pick any CSS selector as you like.

Hope that helps!