使用 geckoFx 创建网站缩略图会导致错误
我正在尝试在 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,我有不同的方法,此方法工作正常,但它们不是适合我的项目。
I'm trying to create an image of a website using geckoFX in WPF/c#. When I run the code I get an error.
error is a Bitmap Width and height using from geckoWebBorwser (int)wWidth and (int) wHeight
error text is (Parameter is not valid) and System.ArgumentException
Error occurs on line
Bitmap bmp = new Bitmap(wWidth, wHeight); //Error here (Parameter is not valid.
System.ArgumentException)
Example code:
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());
}
}
With WebKit.Net this method works fine, With IE webBrowser I have different method and this method works fine, but they are not suitable for my project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个小样本(geckoFx 未知,但看起来很有趣)。以下代码运行正常:
当我没有将浏览器的大小调整为至少为矩形的大小时,我在 browser.DrawToImage 处收到错误。
I created a small sample ( the geckoFx was unknown but looked interesting ). The following code runs fine:
I got an error at browser.DrawToImage when I did not re sized the browser to be at least the size of the rectangle.