开发者

Convert awesomium screenshot to Stream

开发者 https://www.devze.com 2023-03-26 17:13 出处:网络
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

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消