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 开发者_StackOverflow中文版file but get them inmemory. How can I achieve that?
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.
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);
精彩评论