dka*_*apa 1 .net c# c#-4.0 awesomium
我开始在C#中开发,我正在尝试将表面转换为字节缓冲区或图片(以后转换为字节缓冲区).
我在其他问题中看到了这段代码:
string fileName = Path.GetTempFileName();
webView2.Render().SaveToPng(fileName);
byte[] bytes = File.ReadAllBytes(fileName);
File.Delete(fileName);
MemoryStream ms = new MemoryStream(bytes);
Run Code Online (Sandbox Code Playgroud)
但是,webview没有Render(),他没有说我需要导入哪些库.
我在这里停下来:
var view = (WebView)WebCore.Views.Last();
WebCore.Update();
BitmapSurface surface = (BitmapSurface)view.Surface;
surface.??
Run Code Online (Sandbox Code Playgroud)
最近Awesomium有很多无证的变化.
尝试WebView.Surface
而不是WebView.Render
.
using (WebView vw = WebCore.CreateWebView(1024, 768)) {
vw.Source = new Uri("http://www.google.com");
while (vw.IsLoading) {
WebCore.Update();
}
((BitmapSurface)vw.Surface).SaveToJPEG("D:\\google.jpg");
PictureBox1.Load("D:\\google.jpg");
WebCore.Shutdown();
}
Run Code Online (Sandbox Code Playgroud)
评论中指出了另一组变化.只是为了正确起见,这里有一个更新的代码和文档的链接.
using ( webView = WebCore.CreateWebView( 800, 600 ) )
{
webView.Source = new Uri( "http://www.google.com" );
view.LoadingFrameComplete += ( s, e ) =>
{
if ( !e.IsMainFrame )
return;
BitmapSurface surface = (BitmapSurface)view.Surface;
surface.SaveToPNG( "result.png", true );
WebCore.Shutdown();
}
}
WebCore.Run();
Run Code Online (Sandbox Code Playgroud)
资料来源:http://docs.awesomium.net/html/b2fc3fe8-72bd-4baf-980f-b9b9456d5ca4.htm
归档时间: |
|
查看次数: |
3906 次 |
最近记录: |