我正在尝试在 WPF/c# 中使用 geckoFX 创建网站的图像。当我运行代码时,我得到一个错误。
错误是位图宽度和高度,使用来自 geckoWebBorwser (int)wWidth 和 (int) wHeight 错误文本是(参数无效)和 System.ArgumentException
线上出现错误
Bitmap bmp = new Bitmap(wWidth, wHeight); //Error here (Parameter is not valid.
System.ArgumentException)
示例代码:
class GetWebCapture
{
public static BitmapSource GetThumb(Skybound.Gecko.GeckoWebBrowser wb, int w, int h, int wWidth, int wHeight)
{
if (wb != null)
{
Bitmap bmp = new Bitmap(wWidth, wHeight);
Rectangle rec = new Rectangle(0, 0, wWidth, wHeight);
Rectangle rec1 = new Rectangle(0, 0, w, h);
wb.DrawToBitmap(bmp, rec);
Graphics gfx = Graphics.FromImage(bmp);
gfx.CompositingQuality = CompositingQuality.HighQuality;
gfx.SmoothingMode = SmoothingMode.HighQuality;
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.DrawImage(bmp, rec);
Bitmap newImage = new Bitmap(290, 200);
using (Graphics gr = Graphics.FromImage(newImage))
{
gr.SmoothingMode = SmoothingMode.AntiAlias;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(bmp, new Rectangle(0, 0, 290, 200));
}
BitmapSource source = loadBitmaps(newImage);
gfx.Dispose();
bmp.Dispose();
return source;
}
else
{
return null;
}
public static BitmapSource loadBitmaps(System.Drawing.Bitmap source)
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
}
使用 WebKit.Net 这种方法可以正常工作,使用 IE webBrowser 我有不同的方法并且这种方法可以正常工作,但它们不适合我的项目。