利用c#怎么实现一个截长图功能

  介绍

利用c#怎么实现一个截长图功能?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。


1,启用线程线程

void  startPrintScreen (ScreenShotParam  requestParam)   {才能   ,,Thread  Thread =, new 线程(new  ParameterizedThreadStart (do_PrintScreen));   ,,thread.SetApartmentState (ApartmentState.STA);   ,,thread.Start (requestParam);   ,,if  (requestParam.Wait)   ,,{   ,,,thread.Join ();   ,,,FileInfo  result =, new  FileInfo (requestParam.SavePath);   ,,,long  minSize =, 1, *, 1024;//,太小可能是空白圖,重抓   ,,,int  maxRepeat =, 2,,,,,   ,,,while  ((! result.Exists  | |, result.Length  & lt;=, minSize),,,, maxRepeat 祝辞,0)   ,,,{   ,,,,thread =, new 线程(new  ParameterizedThreadStart (do_PrintScreen));   ,,,,thread.SetApartmentState (ApartmentState.STA);   ,,,,thread.Start (requestParam);   ,,,,thread.Join ();   ,,,,maxRepeat——;   ,,,}   ,,}   ,,}

2,模拟浏览器WebBrowser

void  do_PrintScreen (object 参数)   {才能   ,,试一试   ,,{   ,,,ScreenShotParam  ScreenShotParam =, (ScreenShotParam)参数;   ,,,string  requestUrl =, screenShotParam.Url;   ,,,string  savePath =, screenShotParam.SavePath;   ,,,WebBrowser  wb =, new 浏览器();   ,,,wb.ScrollBarsEnabled =,假;   ,,,wb.ScriptErrorsSuppressed =,真的;   ,,,wb.Navigate (requestUrl);   ,,,logger.Debug (“wb.Navigate");   ,,,DateTime  startTime =, DateTime.Now;   ,,,TimeSpan  waitTime =, new 时间间隔(0,0,0,10日,0);//10,s   ,,,while  (wb.ReadyState  !=, WebBrowserReadyState.Complete)   ,,,{   ,,,,Application.DoEvents ();   ,,,,if  (DateTime.Now 安康;startTime 祝辞,waitTime)   ,,,,{   ,,,,,wb.Dispose ();   ,,,,,logger.Debug (“wb.Dispose (), timeout");   ,,,,,返回;   ,,,,}   ,,,}      ,,,wb.Width =, screenShotParam.Left  +, screenShotParam.Width  +, screenShotParam.Left;,//, wb.Document.Body.ScrollRectangle.Width (避掉左右側的邊線);   ,,,wb.Height =, screenShotParam.Top  +, screenShotParam.Height;,//, wb.Document.Body.ScrollRectangle.Height;   ,,,wb.ScrollBarsEnabled =,假;   ,,,wb.Document.Body.Style =,“溢出:hidden";//hide  scroll 酒吧   ,,,var  doc =, (wb.Document.DomDocument), as  mshtml.IHTMLDocument2;   ,,,var  style =, doc.createStyleSheet (““,, 0);   ,,,style.cssText =, @" img {,边框样式:没有,,}“;      ,,,Bitmap  Bitmap =, new 位图(wb.Height wb.Width也);   ,,,wb.DrawToBitmap(位图,new 矩形(0,0,wb.Width,, wb.Height));   ,,,wb.Dispose ();   ,,,logger.Debug (“wb.Dispose ()“);      ,,,bitmap =, CutImage(位图,new 矩形(screenShotParam.Top, screenShotParam.Left,还以为,screenShotParam.Width, screenShotParam.Height));   ,,,bool  needResize =, screenShotParam.Width 祝辞,screenShotParam.ResizeMaxWidth  | |, screenShotParam.Height 祝辞,screenShotParam.ResizeMaxWidth;   ,,,if  (needResize)   ,,,{   ,,,,double  greaterLength =, bitmap.Width 祝辞,bitmap.Height  ?, bitmap.Width :, bitmap.Height;   ,,,,double  ratio =, screenShotParam.ResizeMaxWidth /, greaterLength;   ,,,,bitmap =,调整大小(位图,,比例);   ,,,}      ,,,bitmap.Save (System.Drawing.Imaging.ImageFormat.Gif savePath也);   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

利用c#怎么实现一个截长图功能