AwesomiumWebviewSurfacetoByteBufferorPictureBoxsectionbuffer)。我在其他问题上看到了这段代码:stringfileName=Path.GetTempFileName();webView2.Render().SaveToPng(文件名);byte[]bytes=File.ReadAllBytes(文件名);文件.删除(文件名);MemoryStreamms=newMemoryStream(bytes);但是webview没有Render(),他也没说我需要导入哪些库。我在这里停止:varview=(WebView)WebCore.Views.Last();WebCore.Update();BitmapSurface表面=(BitmapSurface)view.Surface;表面。??Awesomium最近有很多未记录的更改。尝试使用WebView.Surface而不是WebView.Render。使用(WebViewvw=WebCore.CreateWebView(1024,768)){vw.Source=newUri("http://www.google.com");while(vw.IsLoading){WebCore.Update();}((BitmapSurface)vw.Surface).SaveToJPEG("D:\google.jpg");PictureBox1.Load("D:\google.jpg");WebCore.Shutdown();注释中指出了另一组更改。准确地说,这里是更新代码和文档的链接。使用(webView=WebCore.CreateWebView(800,600)){webView.Source=newUri("http://www.google.com");view.LoadingFrameComplete+=(s,e)=>{if(!e.IsMainFrame)返回;BitmapSurface表面=(BitmapSurface)view.Surface;surface.SaveToPNG("result.png",true);WebCore.Shutdown();}}WebCore.Run();资料来源:http://docs.awesomium.net/html/b2fc3fe8-72bd-4baf-980f-b9b9456d5ca4.htm你的意思是这样的?privatestaticbyte[]getWebViewScreenshotAsBytes(refWebViewmyWebView){using(System.IO.MemoryStreamms=newSystem.IO.MemoryStream()){使用(System.Drawing.Bitmapbmp=newSystem.Drawing.Bitmap(myWebView.Width,myWebView.Height,System.Drawing.Imaging.PixelFormat.Format32bppArgb)){位图表面bmpSurface=(BitmapSurface)myWebView.Surface;BitmapDatabmpData=bmp.LockBits(newRectangle(0,0,bmp.Width,bmp.Height),ImageLockMode.WriteOnly,bmp.PixelFormat);bmpSurface.CopyTo(bmpData.Scan0,??bmpSurface.RowSpan,4,false,false);bmp。解锁位(bmpData);bmp.Save(ms,ImageFormat.Png);}返回ms.ToArray();}}双宽度=800;双倍高度=1000;varwebView=WebCore.CreateWebView(宽度,高度,WebViewType.Offscreen);webView.Source=newUri("https://www.google.com/");while(webView.IsLoading){WebCore.Update();}varbitmapSurface=(BitmapSurface)webView.Surface;varwriteableBitmap=newWriteableBitmap(width,height,96,96,PixelFormats.Bgra32,null);writeableBitmap.Lock();bitmapSurface.CopyTo(writeableBitmap.BackBuffer,bitmapSurface.RowSpan,4,false,false);writeableBitmap.AddDirtyRect(newInt32Rect(0,0,width,height));writeableBitmap.Unlock();变种图像=新图像();image.Source=writeableBitmap;缓冲方法呢?那应该是你想要的。以上就是C#学习教程:AwesomiumWebviewSurfacetoByteBuffer或PictureBox分享的全部内容。如果对大家有用,需要了解更多C#学习教程,希望大家多多关注——本文来自网络收藏,不代表立场,如涉及侵权,请点击右转联系管理员删除。如需转载请注明出处:
