SiberianGuy
SiberianGuy

Reputation: 25302

Convert awesomium screenshot to Stream

Here is how I make awesomium screenshot:

webView2.Render().SaveToPng("filePath");

The problem is that I now need not to save bytes to file but get them inmemory. How can I achieve that?

Upvotes: 0

Views: 1063

Answers (2)

Fernando
Fernando

Reputation: 4028

The documentation states that Render() returns an instance of RenderBuffer, which has a property called Buffer, that returns the raw pixel data (as an IntPtr). If you still need a byte array, you could use Marshal.Copy to copy the data into a byte array. This way, you can do it without the need of a temporary file.

Upvotes: 4

Thomas Levesque
Thomas Levesque

Reputation: 292445

The API doesn't seem to provide an overload that takes a stream, but you can always save to a temporary file and load the file into a MemoryStream:

string fileName = Path.GetTempFileName();
webView2.Render().SaveToPng(fileName);
byte[] bytes = File.ReadAllBytes(fileName);
File.Delete(fileName);
MemoryStream ms = new MemoryStream(bytes);

Upvotes: 2

Related Questions