sx.122.gov cn,林俊冰恋,十分爱钢琴谱
using system.io; using system.drawing; using system.drawing.imaging; using system.threading; using system.windows.forms; using system; namespace consoleapp1 { public class capturewebpage { public byte[] picbytes; public capturewebpage(string url) { string bmppath =datetime.now.tostring("yyyymmddhhmmssffff")+".bmp"; bitmap bmp = new bitmap(1000,10000); makepicture(url); bmp = bytetoimage(picbytes); bmp.save(bmppath); } private void makepicture(string url) { thread thread = new thread(delegate () { using (webbrowser browser = new webbrowser()) { browser.scrollbarsenabled = true; browser.allownavigation = true; browser.navigate(url); browser.width = 1024; browser.height =10000; browser.documentcompleted += new webbrowserdocumentcompletedeventhandler(documentcompleted); while (browser.readystate != webbrowserreadystate.complete) { system.windows.forms.application.doevents(); } } }); thread.setapartmentstate(apartmentstate.sta); thread.start(); thread.join(); } private void documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { webbrowser browser = sender as webbrowser; using (bitmap bitmap = new bitmap(browser.width, browser.height)) { browser.drawtobitmap(bitmap, new system.drawing.rectangle(0, 0, browser.width, browser.height)); using (memorystream stream = new memorystream()) { bitmap.save(stream, system.drawing.imaging.imageformat.png); byte[] bytes = stream.toarray(); picbytes = bytes; } } } public static bitmap bytetoimage(byte[] blob) { memorystream mstream = new memorystream(); byte[] pdata = blob; mstream.write(pdata, 0, convert.toint32(pdata.length)); bitmap bm = new bitmap(mstream, false); mstream.dispose(); return bm; } } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论